-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: let next-server handle SWR behavior (#206)
* chore: add local repro of failing test * fix: return stale values for cache entries * fix: give blob a couple seconds to propagate back * fix: ensure lambda doesn't die before the revalidate is done * chore: turn test page into js to prevent it from installing typescript * chore: remove .only * fix: also adjust date header for stale cache serves * fix: set cache-status header for SWR * chore: update route handler test to capture SWR * similar fixes for page router with static revalidate * aaand another test * fix: another test * remove .only * fix first test * fix: route handlers are also cacheable! * test: cache-handler test for page router updated for SWR behavior * chore: remove no longer used CacheHandler helper method * chore remove unused imports and variables used in previously removed method * test: cache-handler test for route handler updated for SWR behavior * test: invoke functions in integration tests in sandboxed child process * test: move request mocking to lambda runner and mock just purge API * Revert "test: move request mocking to lambda runner and mock just purge API" This reverts commit c773508bd1fc1398711fe242e791123642cc5688. * Revert "test: invoke functions in integration tests in sandboxed child process" This reverts commit a834f622b3fd6829032c53654d3600ceeb9492e3. * chore: update msw/node setup to get rid of bunch of warnings * test: split cache-handler tests into 3 separate test suites, one for each fixture * adjust sequencer to run all 3 cache-handler tests in same shard * adjust tests * upgrade vitest * run test suites sequentially * maybe fix lock file * add delay to app router cachehandler tests * test: update fetch-handdler integration tests * Revert "add delay to app router cachehandler tests" This reverts commit b4112c4a53bf2d34086ca349944dfe3a588abbdd. * Revert "maybe fix lock file" This reverts commit db186688fd3f035176176fd76b4b7710ec46436b. * Revert "run test suites sequentially" This reverts commit 548f81d222eb5729e963a494d6a5ebf09dae68e9. * Revert "upgrade vitest" This reverts commit d65ed1a64f16dca2e328fd2fc2d9b79b9ae48448. * Revert "adjust tests" This reverts commit bc620eee8455336e98feeaea83dda5dbe250ddaf. * Revert "adjust sequencer to run all 3 cache-handler tests in same shard" This reverts commit 23f65d3797c69bff58fa24fd6b3ffd9430a31099. * Revert "test: split cache-handler tests into 3 separate test suites, one for each fixture" This reverts commit 6cb1422e5883964a7cf4bfd04b76fb0dbbb902d9. * test: readd delay after reverting setup changes * test: add some debug logs * Revert "test: add some debug logs" This reverts commit 35e92a5b3b0198de9a951aa97f7543839a72a62c. * fix: fix bad merge conflict resolution --------- Co-authored-by: Matt Kane <[email protected]> Co-authored-by: Michal Piechowiak <[email protected]>
- Loading branch information
1 parent
8b17f09
commit d2eeda9
Showing
11 changed files
with
497 additions
and
163 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
33 changes: 33 additions & 0 deletions
33
tests/fixtures/revalidate-fetch/app/dynamic-posts/[id]/page.js
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,33 @@ | ||
const revalidateSeconds = +process.env.REVALIDATE_SECONDS || 5 | ||
const API_BASE = process.env.API_BASE || 'https://api.tvmaze.com/shows/' | ||
|
||
async function getData(params) { | ||
const res = await fetch(new URL(params.id, API_BASE).href, { | ||
next: { revalidate: revalidateSeconds }, | ||
}) | ||
return res.json() | ||
} | ||
|
||
export default async function Page({ params }) { | ||
const data = await getData(params) | ||
|
||
return ( | ||
<> | ||
<h1>Revalidate Fetch (on dynamic page)</h1> | ||
<p>Revalidating used fetch every {revalidateSeconds} seconds</p> | ||
<dl> | ||
<dt>Show</dt> | ||
<dd data-testid="name">{data.name}</dd> | ||
<dt>Param</dt> | ||
<dd data-testid="id">{params.id}</dd> | ||
<dt>Time</dt> | ||
<dd data-testid="date-now">{Date.now()}</dd> | ||
<dt>Time from fetch response</dt> | ||
<dd data-testid="date-from-response">{data.date ?? 'no-date-in-response'}</dd> | ||
</dl> | ||
</> | ||
) | ||
} | ||
|
||
// make page dynamic, but still use fetch cache | ||
export const dynamic = 'force-dynamic' |
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
20 changes: 20 additions & 0 deletions
20
tests/fixtures/simple-next-app/app/stale-cache-serving/app-page/page.js
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,20 @@ | ||
export const dynamic = 'force-dynamic' | ||
|
||
const delay = 3000 | ||
|
||
export default async function Page(props) { | ||
const start = Date.now() | ||
const data = await fetch( | ||
`https://next-data-api-endpoint.vercel.app/api/delay?delay=${delay}`, | ||
{ next: { revalidate: 3 } } | ||
).then((res) => res.json()) | ||
const fetchDuration = Date.now() - start | ||
|
||
return ( | ||
<> | ||
<p id="data"> | ||
{JSON.stringify({ fetchDuration, data, now: Date.now() })} | ||
</p> | ||
</> | ||
) | ||
} |
Oops, something went wrong.