rsnext/test/e2e
Tim Neutkens 48948022c7
Catch redirect() in root layout (#47345)
### What?

Adds the error boundary used to catch `redirect()` above the root
layout.

### Why?

Currently calling `redirect()` in the root layout causes `NEXT_REDIRECT`
to bubble up to the error boundary because we didn't have a
redirect-boundary above the place where the root layout is rendered
client-side.

### How?

- Moved redirect-boundary into a separate file
- Added redirect-boundary around the `cache.subTreeData` in app-router
(around the root layout)

fix NEXT-315 ([link](https://linear.app/vercel/issue/NEXT-315))
Fixes #42556


I've verified the reproduction shown in #42556 has been fixed earlier,
there was another report about calling `redirect()` in the root layout
and that's what this PR fixes.

Since that issue has many comments here's some additional context:
- `redirect()` can only be called during React component rendering.
- This means you can't run `redirect()` in `onClick` or `useEffect()`
handlers.
- Calling `redirect()` in a server component or during prerendering of
client components it will add the right meta tag to trigger a redirect
	- `<meta httpEquiv="refresh" content={`0;url=${redirectUrl}`}>`
- Because of streaming rendering by the time your code runs the browser
will have already received the start of the stream and headers will have
been sent, as such you can't modify the headers, hence why the meta tag
is used instead of `location`.
- Calling `redirect()` in client components is supported while
rendering, e.g. if you have a condition:
	 ```tsx
	'use client'
    import { useState } from 'react'
    import { redirect } from 'next/navigation'
	export function ClientComponent() {
		const [clicked, setClicked] = useState()
		if(clicked) {
			redirect('/another-page')
		}

		return <>
			<button onClick={() => setClicked(true)}>Click to redirect</button>
		</>
	}
	``` 


<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-03-22 09:34:50 +01:00
..
404-page-router Fix error on 404 page when middleware exists (#46303) 2023-02-23 15:55:58 +00:00
app-dir Catch redirect() in root layout (#47345) 2023-03-22 09:34:50 +01:00
basepath BREAKING CHANGE: Enable newNextLinkBehavior (#41459) 2022-10-17 21:20:28 -04:00
browserslist BREAKING CHANGE: Remove browsersListForSwc and change default to legacyBrowsers: false (#41529) 2022-10-19 01:38:39 +00:00
browserslist-extends Ensure browserslist extends works properly (#33890) 2022-02-02 13:23:51 -06:00
config-promise-export Add support for async fn / promise in next.config.js/.mjs (#33662) 2022-02-07 08:48:35 +00:00
dynamic-route-interpolation BREAKING CHANGE: Enable newNextLinkBehavior (#41459) 2022-10-17 21:20:28 -04:00
edge-api-endpoints-can-receive-body feat: enables 'edge' as a possible runtime for API routes (#44045) 2022-12-15 10:08:03 +01:00
edge-async-local-storage feat: enables 'edge' as a possible runtime for API routes (#44045) 2022-12-15 10:08:03 +01:00
edge-can-read-request-body [middleware] add tests for body reading methods #37980 (#41718) 2022-11-01 20:45:58 -07:00
edge-can-use-wasm-files feat: enables 'edge' as a possible runtime for API routes (#44045) 2022-12-15 10:08:03 +01:00
edge-compiler-can-import-blob-assets Add client router filter handling (#46283) 2023-02-22 22:02:31 -08:00
edge-compiler-module-exports-preference Update some flaking tests for edge compiler and rsc (#38344) 2022-07-05 14:37:42 -05:00
edge-configurable-runtime fix(#44077): allow edge runtime for api routes inside src/ folder (#45093) 2023-01-20 11:04:27 -08:00
edge-render-getserversideprops Fix outputting un-necessary trace files for edge functions (#43304) 2022-11-23 18:56:11 -08:00
edge-runtime-uses-edge-light-import-specifier-for-packages [edge] support edge-light exports when bundling edge functions (#45188) 2023-02-16 13:30:34 -08:00
fetch-failures-have-good-stack-traces-in-edge-runtime Fix fetch stack test on deploy 2023-01-27 18:23:27 -08:00
getserversideprops BREAKING CHANGE: Enable newNextLinkBehavior (#41459) 2022-10-17 21:20:28 -04:00
handle-non-hoisted-swc-helpers Ensure @swc/helpers do not rely on hoisting (#38174) 2022-06-29 22:47:44 +00:00
i18n-api-support Enable E2E deploy tests on publish (#37019) 2022-05-21 04:46:16 -05:00
i18n-data-fetching-redirect BREAKING CHANGE: Enable newNextLinkBehavior (#41459) 2022-10-17 21:20:28 -04:00
i18n-default-locale-redirect Handle defaultLocale on client router filter (#47180) 2023-03-16 11:58:02 -07:00
i18n-disallow-multiple-locales i18n Improvements (#47174) 2023-03-17 18:48:09 +00:00
i18n-ignore-redirect-source-locale i18n regression tests and docs for ignore locale in rewrite (#37581) 2022-06-10 14:04:31 -05:00
i18n-ignore-rewrite-source-locale i18n regression tests and docs for ignore locale in rewrite (#37581) 2022-06-10 14:04:31 -05:00
ignore-invalid-popstateevent Move core files to src folder and move JS files to TypeScript (#44405) 2023-01-03 10:05:50 +01:00
instrumentation-hook feat: add support for the src folder for the instrumentation hook (#46529) 2023-02-28 12:08:30 +01:00
instrumentation-hook-src feat: add support for the src folder for the instrumentation hook (#46529) 2023-02-28 12:08:30 +01:00
link-with-api-rewrite BREAKING CHANGE: Enable newNextLinkBehavior (#41459) 2022-10-17 21:20:28 -04:00
manual-client-base-path BREAKING CHANGE: Enable newNextLinkBehavior (#41459) 2022-10-17 21:20:28 -04:00
middleware-base-path BREAKING CHANGE: Enable newNextLinkBehavior (#41459) 2022-10-17 21:20:28 -04:00
middleware-custom-matchers Add missing matcher support (#42660) 2022-11-08 16:48:27 -08:00
middleware-custom-matchers-basepath BREAKING CHANGE: Enable newNextLinkBehavior (#41459) 2022-10-17 21:20:28 -04:00
middleware-custom-matchers-i18n Fix middleware matcher for i18n with negative look ahead (#45504)closes https://github.com/vercel/next.js/issues/40305 2023-02-01 17:30:48 -08:00
middleware-fetches-with-any-http-method [middleware] Support any method when fetching a Request instance (#37540) 2022-06-08 11:00:49 +00:00
middleware-fetches-with-body Fix E2E deploy test for API bodies (#41542) 2022-10-18 18:07:39 -07:00
middleware-general Fix middleware 404 prefetch case (#46782) 2023-03-05 02:32:53 +00:00
middleware-matcher BREAKING CHANGE: Enable newNextLinkBehavior (#41459) 2022-10-17 21:20:28 -04:00
middleware-redirects Update client router filter to separate redirects handling (#46752) 2023-03-03 16:02:02 -08:00
middleware-request-header-overrides feat: enables 'edge' as a possible runtime for API routes (#44045) 2022-12-15 10:08:03 +01:00
middleware-responses Enable allowMiddlewareResponseBody by default (#44224) 2022-12-21 18:40:58 +00:00
middleware-rewrites Update test env for E2E deploy mode (#44937) 2023-01-16 15:39:54 -08:00
middleware-shallow-link Update test env variable passing (#44912) 2023-01-15 23:20:16 -08:00
middleware-trailing-slash Pass through original matcher source in manifest (#46753) 2023-03-03 16:55:41 -08:00
multi-zone Fix shared entries/invalidators module scope (#46533) 2023-02-28 10:17:28 -08:00
new-link-behavior Add types as a default dependency into tests (#44140) 2022-12-19 19:05:53 +01:00
next-font Remove experimental fontLoaders option from next.config.js (#46886) 2023-03-13 21:34:43 +00:00
next-head Fix document head with react 18 (#37443) 2022-06-04 10:30:42 +00:00
next-image-forward-ref Add ref forwarding for next/image (#43193) 2022-11-25 15:08:50 +00:00
next-script test(next-script): teardown next-dev instance via jest hooks (#46383) 2023-02-24 13:28:05 -08:00
no-eslint-warn-with-no-eslint-config fix: detect ESLint config in package.json (#40158) 2022-09-01 16:23:03 +00:00
nonce-head-manager correctly assess node equality when nonce attribute is present (#27573) 2021-11-10 19:31:32 -06:00
og-api Add image generation test to app route (#46449) 2023-02-27 19:29:09 +01:00
opentelemetry Improve OTEL spans naming (#47209) 2023-03-20 17:17:23 +00:00
postcss-config-cjs Fix postcss deploy e2e test (#38782) 2022-07-18 20:21:35 -05:00
prerender chore: show large data warning once per page on prod (#46323) 2023-02-25 12:29:59 -08:00
prerender-native-module Migrate prerender tests to new set-up (#29245) 2021-09-21 16:21:05 +02:00
proxy-request-with-middleware Fix e2e deploy test for Node.js v18 (#43109) 2022-11-18 18:04:17 -08:00
reload-scroll-backforward-restoration BREAKING CHANGE: Enable newNextLinkBehavior (#41459) 2022-10-17 21:20:28 -04:00
repeated-forward-slashes-error Add page path to repeated slashes in href error (#46557) 2023-03-01 00:10:11 -08:00
skip-trailing-slash-redirect Ensure chained middleware rewrites work properly (#46866) 2023-03-06 23:21:42 -08:00
ssr-react-context fix: react dev bundle is picked in prod mode (#39221) 2022-08-01 14:21:42 +00:00
streaming-ssr feat: enables 'edge' as a possible runtime for API routes (#44045) 2022-12-15 10:08:03 +01:00
styled-jsx Revert "Merge e2e test node_modules (#40926)" (#40974) 2022-09-28 08:08:46 +00:00
swc-warnings Add experimental flag to force SWC transforms (#36789) 2022-05-10 10:33:31 +00:00
switchable-runtime Pass through original matcher source in manifest (#46753) 2023-03-03 16:55:41 -08:00
test-template/{{ toFileName name }} Change test template to use TS and improve template for app-dir (#44227) 2023-01-06 20:36:47 +00:00
test-utils-tests/basic Cache package lock when running tests to speed up installation (#44520) 2023-01-03 11:55:28 +01:00
trailingslash-with-rewrite fix: properly handle trailingSlash: true and rewrites (#43641) 2022-12-02 22:04:36 -08:00
transpile-packages Move transpilePackages out of experimental (#44194) 2022-12-20 17:27:30 +00:00
type-module-interop Update test env variable passing (#44912) 2023-01-15 23:20:16 -08:00
undici-fetch Skip experimental undici test for deploy mode (#41006) 2022-09-28 11:28:06 -07:00
yarn-pnp/test Gracefully handle telemetry not being available (#44986) 2023-01-17 16:00:22 -08:00
basepath-trailing-slash.test.ts Ensure trailingSlash is correct for index with query (#29217) 2021-09-21 16:18:42 +02:00
basepath.test.ts Update some flakey test cases (#43247) 2022-11-22 09:50:03 -08:00
example-file.txt Update pnpm new-test to use createNextDescribe (#44147) 2022-12-19 20:08:50 +01:00
example.txt Fix test template example (#44170) 2022-12-19 16:31:28 -08:00
prerender-crawler.test.ts Add crawler blocking for fallback: true (#29121) 2021-09-16 11:01:28 -05:00
prerender-native-module.test.ts Update resolving for node_modules trace pass (#30985) 2021-11-04 20:09:37 -05:00
prerender.test.ts chore: show large data warning once per page on prod (#46323) 2023-02-25 12:29:59 -08:00