forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ppr: prevent CacheNode.loading from being cleared on popstate (vercel…
…#68488) When PPR was enabled, the "restore" action in PPR was causing the `loading` boundary for the visible `CacheNode` to lose it's `loading`. This caused the `Suspense` boundary that contained the loading information to disappear, which in turn caused the tree to remount since it wraps all the page children. I can't think of a reason why we'd not want to preserve the existing `loading` data here, as it's not tied to the prefetch. closes vercel#68484 --------- Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
- Loading branch information
1 parent
dd40c20
commit 99a9282
Showing
7 changed files
with
73 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use client' | ||
|
||
import * as React from 'react' | ||
|
||
export function Input() { | ||
const [query, setQuery] = React.useState('') | ||
|
||
React.useEffect(() => { | ||
if (!query) { | ||
return | ||
} | ||
|
||
window.history.replaceState({ query }, null, `?q=${query}`) | ||
}, [query]) | ||
|
||
return ( | ||
<input | ||
onChange={(event) => setQuery(event.currentTarget.value)} | ||
value={query} | ||
/> | ||
) | ||
} |
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,9 @@ | ||
import * as React from 'react' | ||
|
||
export default function Root({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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,5 @@ | ||
import * as React from 'react' | ||
|
||
export default function Loading() { | ||
return <p>Loading...</p> | ||
} |
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,12 @@ | ||
import * as React from 'react' | ||
import { Input } from './input' | ||
|
||
export default function Page() { | ||
return ( | ||
<main> | ||
<label> | ||
Enter a query: <Input /> | ||
</label> | ||
</main> | ||
) | ||
} |
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,10 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
experimental: { | ||
ppr: true, | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |
14 changes: 14 additions & 0 deletions
14
test/e2e/app-dir/ppr-history-replace-state/ppr-history-replace-state.test.ts
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,14 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('ppr-history-replace-state', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should not remount component', async () => { | ||
const browser = await next.browser('/') | ||
await await browser.elementByCss('input').type('a') | ||
// When the input is remounted, its value is cleared. | ||
expect(await browser.elementByCss('input').getValue()).toBe('a') | ||
}) | ||
}) |