Open yongholeeme opened 2 weeks ago
Going onto the network tab I noticed there's a fetch call every 5 click and there's no fetch call in between those 5 click
@Sahil4883, those fetch calls are triggered by router.refresh()
. It's called whenever foo
query is updated with a value greater than 5. https://github.com/yongholeeme/reproduction-bug-history-api-in-effect-nextjs/blob/main/Bug.jsx#L15-L20
I wrote this code to show that window.history.replaceState()
in first effect execution doesn't synchronize with next router.
https://github.com/user-attachments/assets/794fe765-240a-4923-b4f8-9120c75adfda
Link to the code that reproduces this issue
https://github.com/yongholeeme/reproduction-bug-history-api-in-effect-nextjs/blob/main/Bug.jsx
To Reproduce
foo
's value has to be changedbar
according to1. When query
foois over 5, call window.history.replaceState() in effect
?foo=bar
, butconsole.log()
don't be executed in useEffect hassearchParams
dependency.router.refresh()
,?foo=100
query is back.https://github.com/user-attachments/assets/593b9697-e790-4cea-a877-1e824671a6a2
Current vs. Expected behavior
Wherever
window.history.replaceState()
is called, it's be synchronized with Router.Provide environment information
Which area(s) are affected? (Select all that apply)
Navigation
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local), Vercel (Deployed)
Additional context
No response