b95bc4b74b
In Next 12, `router.replace()` treats the page props cache as authoritative when fetching SSG props in preview mode. This makes sense outside preview mode (static props won't change), but within preview mode this prevents reloading the preview data dynamically without force-refreshing the page. This PR fixes the problem by instructing Next to bypass the props cache if it's an SSG route AND preview mode is on. Repro: https://github.com/kamsar/next-replace-previewmode-staticprops/blob/main/pages/index.js ## Bug - [x] Related issues linked using `fixes #number`: Fixes https://github.com/vercel/next.js/issues/30756 - [ ] Integration tests added: Did not find existing tests for the router, but I'd be happy to write one if someone could point me in the right direction. |
||
---|---|---|
.. | ||
.stats-app | ||
development | ||
e2e | ||
integration | ||
lib | ||
production | ||
unit | ||
.eslintrc.json | ||
.gitignore | ||
jest-setup-after-env.ts | ||
readme.md | ||
test-file.txt |
Writing tests for Next.js
Test types in Next.js
- e2e: These tests will run against
next dev
andnext start
- development: These tests only run against
next dev
- production: These tests will run against
next start
. - integration: These tests run misc checks and modes and is where tests used to be added before we added more specific folders. We should not add any more tests here.
- unit: These are very fast tests that should run without a browser or running next and should be testing a specific utility.
For the e2e, production, and development tests the createNext
utility should be used and an example is available here. This creates an isolated Next.js install to ensure nothing in the monorepo is relied on accidentally causing incorrect tests.
All new tests should be written in TypeScript either .ts
(or .tsx
for unit tests). This will help ensure we catch smaller issues in tests that could cause flakey or incorrect tests.
Best practices
- When checking for a condition that might take time, ensure it is waited for either using the browser
waitForElement
or using thecheck
util innext-test-utils
. - When applying a fix, ensure the test fails without the fix. This makes sure the test will properly catch regressions.