-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix refresh behavior for discarded actions (#64532)
When an action is marked as "discarded", we enqueue a refresh, since the navigation event will be invoked immediately without waiting for the action to finish. We refresh because it's possible that the discarded action triggered some sort of mutation/revalidation, and we want the router to still be able to respond to that new data. However there's a bug in this logic -- it'll only enqueue the refresh action if there were no other actions in the queue, ignoring the case where something is still in the queue. This makes sure that the refresh is handled after `runRemainingActions` finishes. When adding a test for the server component case (which doesn't hit this refresh branch), I noticed `LayoutRouter` caused React to suspend indefinitely, because it got stuck in the `use(unresolvedThenable)` case. We should only suspend indefinitely if we kicked off a the `SERVER_PATCH` action, as otherwise it's possible nothing will ever break out of that branch. Fixes #64517 Closes NEXT-3124
- Loading branch information
Showing
7 changed files
with
91 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use client' | ||
|
||
import { useRouter } from 'next/navigation' | ||
|
||
export default function RedirectClientComponent({ action }) { | ||
const router = useRouter() | ||
return ( | ||
<button | ||
id="redirect-revalidate-client" | ||
onClick={async () => { | ||
await action() | ||
router.push('/revalidate?foo=bar') | ||
}} | ||
> | ||
redirect + revalidate (client component) | ||
</button> | ||
) | ||
} |
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
6 changes: 6 additions & 0 deletions
6
test/e2e/app-dir/navigation/app/metadata-await-promise/nested/loading.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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
'use client' | ||
import { useEffect } from 'react' | ||
|
||
export default function Loading() { | ||
useEffect(() => { | ||
window.shownLoading = true | ||
}, []) | ||
return <div id="loading">Loading</div> | ||
} |
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