-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix standalone rendering for unmatched _next routes (#51611)
Request data flow in the server ``` request ---> router worker (1) ---> ipc ---> render worker app (2) |-----> render worker pages (3) ``` When it's hitting `_next/*` unmatched routes in standalone server, it will render 404, but when you hit `_next/*` it will render app not-found as the app router is always enabled, but router worker isn't set up with require-hook for proper built-in react version, then the app-render will fail with `./server.edge` exports not found error. We detect if it's in the render worker, then do the app paths rendering instead of directly looking up for app paths in route worker. This could avoid unexpected accesses to the app-render Fixes #51482 Fixes #50232 Closes #51506 Reverts changes in #51172 fix NEXT-1260
- Loading branch information
Showing
13 changed files
with
71 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function NotFound() { | ||
return 'app-not-found' | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'standalone mode - metadata routes', | ||
{ | ||
files: __dirname, | ||
dependencies: { | ||
swr: 'latest', | ||
}, | ||
}, | ||
({ next }) => { | ||
beforeAll(async () => { | ||
// Hide source files to make sure route.js can read files from source | ||
// in order to hit the prerender cache | ||
await next.renameFolder('app', 'app_hidden') | ||
}) | ||
|
||
it('should handle metadata icons correctly', async () => { | ||
const faviconRes = await next.fetch('/favicon.ico') | ||
const iconRes = await next.fetch('/icon.svg') | ||
expect(faviconRes.status).toBe(200) | ||
expect(iconRes.status).toBe(200) | ||
}) | ||
|
||
it('should handle correctly not-found.js', async () => { | ||
const res = await next.fetch('/not-found/does-not-exist') | ||
expect(res.status).toBe(404) | ||
const html = await res.text() | ||
expect(html).toContain('app-not-found') | ||
}) | ||
|
||
it('should handle private _next unmatched route correctly', async () => { | ||
const res = await next.fetch('/_next/does-not-exist') | ||
expect(res.status).toBe(404) | ||
const html = await res.text() | ||
expect(html).toContain('app-not-found') | ||
}) | ||
|
||
it('should handle pages rendering correctly', async () => { | ||
const browser = await next.browser('/hello') | ||
expect(await browser.elementByCss('#content').text()).toBe('hello-bar') | ||
}) | ||
} | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import useSWR, { useSWRConfig } from 'swr' | ||
|
||
export default function Page({ foo }) { | ||
const { data } = useSWR('hello', (v) => v, { fallbackData: 'hello' }) | ||
useSWRConfig() // call SWR context | ||
|
||
return <div id="content">{`${data}-${foo}`}</div> | ||
} | ||
|
||
export function getServerSideProps() { | ||
return { | ||
props: { | ||
foo: 'bar', | ||
}, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.