rsnext/test/e2e/app-dir
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
..
actions Support passing both closure arguments and parameters (#47212) 2023-03-16 19:11:13 -07:00
app Add searchParams to leaf cache key (#47312) 2023-03-20 19:57:29 +01:00
app-a11y Implement route announcer for app dir (#47018) 2023-03-13 13:09:22 -07:00
app-alias Add experimental route type checking (#45761) 2023-02-11 15:06:39 +00:00
app-basepath Prefix basePath in navigate and prefix methods in app router (#45771) 2023-02-10 13:01:00 +00:00
app-css Fix CSS not being bundled in app dir (#45787) 2023-03-17 17:38:19 +00:00
app-edge Pass through original matcher source in manifest (#46753) 2023-03-03 16:55:41 -08:00
app-edge-global Move tests into their test folder (#44183) 2022-12-21 14:16:52 +01:00
app-external Fix client boundary defined in a module (#46171) 2023-02-21 15:20:45 +00:00
app-middleware Update client router filter to separate redirects handling (#46752) 2023-03-03 16:02:02 -08:00
app-prefetch Add missing isRootLayout when creating optimistic tree (#45899) 2023-02-14 14:06:58 +01:00
app-rendering Move tests into their test folder (#44183) 2022-12-21 14:16:52 +01:00
app-routes Fix bad route path for custom metadata routes (#47286) 2023-03-21 15:55:32 +00:00
app-routes-trailing-slash Fix route.js trailingSlash handling (#46185) 2023-02-21 17:19:56 -08:00
app-static Marks app paths in dev as supporting dynamic html (#46848) 2023-03-21 20:55:04 +00:00
app-validation Add Zod and router state validation (#46962) 2023-03-10 13:37:45 +00:00
asset-prefix Change NextInstance.fetch Signature (#44575) 2023-01-05 16:31:03 +01:00
async-component-preload Move tests into their test folder (#44183) 2022-12-21 14:16:52 +01:00
autoscroll-with-css-modules Fix issue where layout-router wouldn't auto-scroll if we imported styles or fonts (#45487) 2023-02-07 12:03:18 +00:00
back-button-download-bug Move tests into their test folder (#44183) 2022-12-21 14:16:52 +01:00
create-next-app-template Migrate create-next-app and e2e tests to Metadata API. (#45819) 2023-02-23 23:40:06 +00:00
create-root-layout Migrate create-next-app and e2e tests to Metadata API. (#45819) 2023-02-23 23:40:06 +00:00
dynamic Separate next/dynamic implementation for app and pages (#45565) 2023-02-04 01:45:35 +00:00
dynamic-href Move tests into their test folder (#44183) 2022-12-21 14:16:52 +01:00
edge-runtime-node-compatibility [edge] limit the api surface of util (#47292) 2023-03-20 10:29:00 +01:00
global-error Update test env variable passing (#44912) 2023-01-15 23:20:16 -08:00
head Add ISR handling for app routes (#46133) 2023-02-21 15:25:42 -08:00
hooks Separate navigation and hooks tests into new test suites (#45766) 2023-02-10 00:38:39 +00:00
import Move tests into their test folder (#44183) 2022-12-21 14:16:52 +01:00
interpolability-with-pages Update test env for E2E deploy mode (#44937) 2023-01-16 15:39:54 -08:00
layout-params Move tests into their test folder (#44183) 2022-12-21 14:16:52 +01:00
mdx Add additional tests for @next/mdx (#45585)Co-authored-by: Shu Ding <g@shud.in> 2023-02-11 13:37:00 +01:00
metadata Fix: only apply metadata dynamic image routes convention for app dir (#47367) 2023-03-21 18:25:20 +00:00
metadata-dynamic-routes Support manifest.json static and dynamic route (#47240) 2023-03-17 12:11:34 -07:00
navigation Emit late streaming meta tags (#47207) 2023-03-17 14:37:00 +00:00
next-font Remove experimental fontLoaders option from next.config.js (#46886) 2023-03-13 21:34:43 +00:00
next-image Move tests into their test folder (#44183) 2022-12-21 14:16:52 +01:00
pages-to-app-routing Add client router filter handling (#46283) 2023-02-22 22:02:31 -08:00
parallel-routes-and-interception Add tests for parallel routes / interception and handle router state patch merging client-side (#45615) 2023-02-13 16:12:44 +01:00
rewrites-redirects Update test env for E2E deploy mode (#44937) 2023-01-16 15:39:54 -08:00
root-layout Test navigation between multiple root layouts (#43762) 2023-01-05 13:27:29 +01:00
root-layout-redirect Catch redirect() in root layout (#47345) 2023-03-22 09:34:50 +01:00
route-page-manifest-bug Fix manifest error when using route.js (#46102) 2023-02-18 20:31:49 +01:00
router-autoscroll Fix issue where layout-router wouldn't auto-scroll if we imported styles or fonts (#45487) 2023-02-07 12:03:18 +00:00
rsc-basic Adjust API route loader (#46726 2023-03-04 01:18:07 +01:00
searchparams-static-bailout Opt-in to dynamic rendering when reading searchParams (#46205) 2023-03-16 21:46:35 +01:00
similar-pages-paths Fix conflict dev entry key between app and pages (#46832) 2023-03-07 12:27:10 -08:00
test-template/{{ toFileName name }} Add additional tests for @next/mdx (#45585)Co-authored-by: Shu Ding <g@shud.in> 2023-02-11 13:37:00 +01:00
trailingslash Change NextInstance.fetch Signature (#44575) 2023-01-05 16:31:03 +01:00
use-selected-layout-segment-s Update test env variable passing (#44912) 2023-01-15 23:20:16 -08:00
with-babel Move tests into their test folder (#44183) 2022-12-21 14:16:52 +01:00