rsnext/test
Zack Tanner dd57054647
Fix parallel routes with server actions / revalidating router cache (#59585)
### What?
There are a bunch of different bugs caused by the same underlying issue,
but the common thread is that performing any sort of router cache update
(either through `router.refresh()`, `revalidatePath()`, or `redirect()`)
inside of a parallel route would break the router preventing subsequent
actions, and not resolve any pending state such as from `useFormState`.

### Why?
`applyPatch` is responsible for taking an update response from the
server and merging it into the client router cache. However, there's
specific bailout logic to skip over applying the patch to a
`__DEFAULT__` segment (which corresponds with a `default.tsx` page).
When the router detects a cache node that is expected to be rendered on
the page but contains no data, the router will trigger a lazy fetch to
retrieve the data that's expected to be there
([ref](5adacb6912/packages/next/src/client/components/layout-router.tsx (L359-L370)))
and then update the router cache once the data resolves
([ref](5adacb6912/packages/next/src/client/components/layout-router.tsx (L399-L404))).

This is causing the router to get stuck in a loop: it'll fetch the data
for the cache node, send the data to the router reducer to merge it into
the existing cache nodes, skip merging that data in for `__DEFAULT__`
segments, and repeat.

### How?
We currently assign `__DEFAULT__` to have `notFound()` behavior when
there isn't a `default.tsx` component for a particular segment. This
makes it so that when loading a page that renders a slot without slot
content / a `default`, it 404s. But when performing a client-side
navigation, the intended behavior is different: we keep whatever was in
the `default` slots place, until the user refreshes the page, which
would then 404.

However, this logic is incorrect when triggering any of the above
mentioned cache node revalidation strategies: if we always skip applying
to the `__DEFAULT__` segment, slots will never properly handle reducer
actions that rely on making changes to their cache nodes.

This splits these different `applyPatch` functions: one that will apply
to the full tree, and another that'll apply to everything except the
default segments with the existing bailout condition.

Fixes #54173
Fixes #58772
Fixes #54723
Fixes #57665

Closes NEXT-1706
Closes NEXT-1815
Closes NEXT-1812
2023-12-15 15:51:14 +00:00
..
.stats-app tweak stats action to pull in runtime sizes (#58005) 2023-11-03 23:39:37 +00:00
development Add tests for invalid React server APIs (#59622) 2023-12-15 10:12:46 +01:00
e2e Fix parallel routes with server actions / revalidating router cache (#59585) 2023-12-15 15:51:14 +00:00
examples feat(cli): introduce --tailwind flag (#46927) 2023-03-16 16:06:27 +01:00
integration test(integration): adjust fixture to work with turbopack (#59595) 2023-12-13 13:17:52 -08:00
lib fix(playwright): teardown when global quit force terminates browser (#59548) 2023-12-12 15:18:47 -08:00
production transpilePackages should override default settings for external packages (#59385) 2023-12-13 19:04:57 +01:00
unit Resolve build issues with symlinked files (#57412) 2023-12-04 11:43:13 +01:00
.gitignore ci(workflow): enable test trace upload (#51107) 2023-06-12 17:14:13 +00:00
build-turbopack-tests-manifest.d.ts Update Turbopack test manifest from GitHub Actions artifact (#58394) 2023-11-24 16:48:12 +01:00
build-turbopack-tests-manifest.js Update Turbopack test manifest (#59109) 2023-12-01 10:16:28 +00:00
get-test-filter.js Enable PPR tests for test suites (#59030) 2023-11-29 03:22:45 +00:00
jest-setup-after-env.ts Decrease default test timeouts (#56116) 2023-09-27 23:55:20 +00:00
ppr-tests-manifest.json Partial Pre Rendering Headers (#59447) 2023-12-14 13:14:06 -07:00
readme.md
test-file.txt
tsconfig.json Fix test/tsconfig.json alias for internal test utils (#59570) 2023-12-13 13:57:23 +00:00
turbopack-tests-manifest.json Add tests for invalid React server APIs (#59622) 2023-12-15 10:12:46 +01:00

See Testing for more information on how you can run/write/debug tests for Next.js.