"description": "TypeError: useState only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component",
"description": "Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.",
"description": "Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.",
@@ -81,19 +81,32 @@ describe('Error overlay for hydration errors in Pages router', () => {
// Pages Router uses React version without Owner Stacks hence the empty `stack`
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Mismatch>
[
{
"componentStack": "<Mismatch>
<div>
<main>
+ "server"
- "client"",
"count": 2,
"description": "Text content did not match. Server: "server" Client: "client"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Text content did not match. Server: "server" Client: "client"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Mismatch>
<div>
<main>
+ "server"
- "client"",
"description": "Text content did not match. Server: "server" Client: "client"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -112,7 +125,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
- server
...
...",
"count": 1,
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
...
...
@@ -172,17 +184,38 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Mismatch>
[
{
"componentStack": "<Mismatch>
> <div>
> <main>",
"count": 3,
"description": "Expected server HTML to contain a matching <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Expected server HTML to contain a matching <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Mismatch>
> <div>
> <main>",
"description": "Expected server HTML to contain a matching <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Mismatch>
> <div>
> <main>",
"description": "Expected server HTML to contain a matching <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -199,7 +232,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
+ <main className="only">
...
...",
"count": 1,
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
...
...
@@ -244,18 +276,41 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Mismatch>
[
{
"componentStack": "<Mismatch>
<div>
> <div>
> "second"",
"count": 3,
"description": "Expected server HTML to contain a matching text node for "second" in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Expected server HTML to contain a matching text node for "second" in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Mismatch>
<div>
> <div>
> "second"",
"description": "Expected server HTML to contain a matching text node for "second" in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Mismatch>
<div>
> <div>
> "second"",
"description": "Expected server HTML to contain a matching text node for "second" in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -275,7 +330,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
...
...
...",
"count": 1,
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
...
...
@@ -314,16 +368,26 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Mismatch>
[
{
"componentStack": "<Mismatch>
> <div>",
"count": 2,
"description": "Did not expect server HTML to contain a <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Did not expect server HTML to contain a <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Mismatch>
> <div>",
"description": "Did not expect server HTML to contain a <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -341,7 +405,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
- <main className="only">
...
...",
"count": 1,
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
...
...
@@ -376,18 +439,30 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Mismatch>
[
{
"componentStack": "<Mismatch>
<div>
> <div>
> "only"",
"count": 2,
"description": "Did not expect server HTML to contain the text node "only" in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Did not expect server HTML to contain the text node "only" in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Mismatch>
<div>
> <div>
> "only"",
"description": "Did not expect server HTML to contain the text node "only" in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -405,7 +480,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
- only
...
...",
"count": 1,
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
...
...
@@ -454,16 +528,35 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Page>
[
{
"componentStack": "<Page>
> <table>",
"count": 3,
"description": "Expected server HTML to contain a matching <table> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Expected server HTML to contain a matching <table> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
> <table>",
"description": "Expected server HTML to contain a matching <table> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
> <table>",
"description": "Expected server HTML to contain a matching <table> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -481,7 +574,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
- test
...
...",
"count": 1,
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
...
...
@@ -524,16 +616,35 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Page>
[
{
"componentStack": "<Page>
> <table>",
"count": 3,
"description": "Expected server HTML to contain a matching <table> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Expected server HTML to contain a matching <table> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
> <table>",
"description": "Expected server HTML to contain a matching <table> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
> <table>",
"description": "Expected server HTML to contain a matching <table> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -551,7 +662,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
- {" 123"}
...
...",
"count": 1,
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
...
...
@@ -599,18 +709,41 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Mismatch>
[
{
"componentStack": "<Mismatch>
> <div>
<Suspense>
> <main>",
"count": 3,
"description": "Expected server HTML to contain a matching <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Expected server HTML to contain a matching <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Mismatch>
> <div>
<Suspense>
> <main>",
"description": "Expected server HTML to contain a matching <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Mismatch>
> <div>
<Suspense>
> <main>",
"description": "Expected server HTML to contain a matching <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -629,7 +762,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
...
...
...",
"count": 1,
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
...
...
@@ -704,17 +836,38 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Page>
[
{
"componentStack": "<Page>
> <p>
> <p>",
"count": 3,
"description": "Expected server HTML to contain a matching <p> in <p>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Expected server HTML to contain a matching <p> in <p>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
> <p>
> <p>",
"description": "Expected server HTML to contain a matching <p> in <p>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
> <p>
> <p>",
"description": "Expected server HTML to contain a matching <p> in <p>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -732,7 +885,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <p>
...
...",
"count": 1,
"description": "In HTML, <p> cannot be a descendant of <p>.
This will cause a hydration error.",
"environmentLabel": null,
...
...
@@ -779,19 +931,44 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Page>
[
{
"componentStack": "<Page>
<div>
<div>
> <p>
> <div>",
"count": 3,
"description": "Expected server HTML to contain a matching <div> in <p>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Expected server HTML to contain a matching <div> in <p>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
<div>
<div>
> <p>
> <div>",
"description": "Expected server HTML to contain a matching <div> in <p>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
<div>
<div>
> <p>
> <div>",
"description": "Expected server HTML to contain a matching <div> in <p>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -809,7 +986,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <div>
...
...",
"count": 1,
"description": "In HTML, <div> cannot be a descendant of <p>.
This will cause a hydration error.",
"environmentLabel": null,
...
...
@@ -848,17 +1024,38 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Page>
[
{
"componentStack": "<Page>
> <div>
> <tr>",
"count": 3,
"description": "Expected server HTML to contain a matching <tr> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Expected server HTML to contain a matching <tr> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
> <div>
> <tr>",
"description": "Expected server HTML to contain a matching <tr> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
> <div>
> <tr>",
"description": "Expected server HTML to contain a matching <tr> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -876,7 +1073,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <tr>
...
...",
"count": 1,
"description": "In HTML, <tr> cannot be a child of <div>.
This will cause a hydration error.",
"environmentLabel": null,
...
...
@@ -917,21 +1113,50 @@ describe('Error overlay for hydration errors in Pages router', () => {
if(isReact18){
awaitexpect(browser).toDisplayRedbox(`
{
"componentStack": "<Page>
[
{
"componentStack": "<Page>
<p>
<span>
<span>
<span>
> <span>
> <p>",
"count": 3,
"description": "Expected server HTML to contain a matching <p> in <span>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
"description": "Expected server HTML to contain a matching <p> in <span>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
<p>
<span>
<span>
<span>
> <span>
> <p>",
"description": "Expected server HTML to contain a matching <p> in <span>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
{
"componentStack": "<Page>
<p>
<span>
<span>
<span>
> <span>
> <p>",
"description": "Expected server HTML to contain a matching <p> in <span>.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
...
...
@@ -953,7 +1178,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <p>
...
...",
"count": 1,
"description": "In HTML, <p> cannot be a descendant of <p>.
// TODO(veil): Where is the stackframe for app/page.js?
awaitexpect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: Route / with \`dynamic = "error"\` couldn't be rendered statically because it used \`headers\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
"description": "Error: Route "/error" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random",
"description": "Error: Route "/error" used \`Math.random()\` outside of \`"use cache"\` and without explicitly calling \`await connection()\` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random",
"description": "Error: Route "/no-accessed-data": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. We don't have the exact line number added to error messages yet but you can see which component in the stack below. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense",
// Ideally, it would be issued from the async Component instead but that's
// harder to implement.
awaitexpect(browser).toDisplayCollapsedRedbox(`
{
"count": 2,
"description": "<Page> is an async Client Component. Only Server Components can be async at the moment. This error is often caused by accidentally adding \`'use client'\` to a module that was originally written for the server.",
"environmentLabel": null,
"label": "Console Error",
"source": null,
"stack": [],
}
[
{
"description": "<Page> is an async Client Component. Only Server Components can be async at the moment. This error is often caused by accidentally adding \`'use client'\` to a module that was originally written for the server.",
"environmentLabel": null,
"label": "Console Error",
"source": null,
"stack": [],
},
{
"description": "A component was suspended by an uncached promise. Creating promises inside a Client Component or hook is not yet supported, except via a Suspense-compatible library or framework.",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"description": "In HTML, <p> cannot be a descendant of <p>.
This will cause a hydration error.",
"environmentLabel": null,
"label": "Console Error",
"source": "app/two-issues/page.tsx (10:7) @ Page
> 10 | <p>nest</p>
| ^",
"stack": [
"p <anonymous> (0:0)",
"Page app/two-issues/page.tsx (10:7)",
],
],
"notes": null,
}
`)
// Hydration console.error
// - contains a diff
// - no notes
expect(secondError).toMatchInlineSnapshot(`
{
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/two-issues/page.tsx (10:7) @ Page
> 10 | <p>nest</p>
| ^",
"stack": [
"p <anonymous> (0:0)",
"Page app/two-issues/page.tsx (10:7)",
],
],
"notes": "- A server/client branch \`if (typeof window !== 'undefined')\`.
- Variable input such as \`Date.now()\` or \`Math.random()\` which changes each time it's called.
- Date formatting in a user's locale which doesn't match the server.
- External changing data without sending a snapshot of it along with the HTML.
- Invalid HTML tag nesting.
It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.",
}
},
]
`)
})
it('should display runtime error separately from hydration errors',async()=>{
"description": "Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
"description": "Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
"description": "Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
"description": "Error: Additional keys were returned from \`getStaticProps\`. Properties intended for your component must be nested under the \`props\` key, e.g.:
"description": "Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
},
]
`)
}else{
awaitexpect(browser).toDisplayRedbox(`
{
"count": ${isReact18?3:1},
"description": "Error: An Expected error occurred",
"description": "Error: Circular structure in "getInitialProps" result of page "/circular-json-error". https://nextjs.org/docs/messages/circular-structure",
"description": "Error: Circular structure in "getInitialProps" result of page "/circular-json-error". https://nextjs.org/docs/messages/circular-structure",
"description": "Error: "InstanceInitialPropsPage.getInitialProps()" is defined as an instance method - visit https://nextjs.org/docs/messages/get-initial-props-as-an-instance-method for more information.",
"description": "Error: No children were passed to <Link> with \`href\` of \`/about\` but one child is required https://nextjs.org/docs/messages/link-no-children",
"description": "Error: Multiple children were passed to <Link> with \`href\` of \`/\` but only one child is supported https://nextjs.org/docs/messages/link-multiple-children
Open your browser's console to view the Component stack trace.",