SearchParams Sync Issue During First Effect Execution with window.history.replaceState()
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
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
I created and deployed reproduction: https://reproduction-bug-history-api-in-effect-nextjs.vercel.app
- When query
foois over 5, callwindow.history.replaceState()in effect- When
searchParamsis changed, callconsole.log()to watchsearchParams- When clicked the button, query
foois updated by random number (0 ~ 9)
- When connect https://reproduction-bug-history-api-in-effect-nextjs.vercel.app?foo=100,
foo's value has to be changedbaraccording to1. When queryfoois over 5, call window.history.replaceState() in effect - It seems to be changed to
?foo=bar, butconsole.log()don't be executed in useEffect hassearchParamsdependency. - Even after calling
router.refresh(),?foo=100query 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
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.0.0: Tue Sep 24 23:37:13 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T8112
Available memory (MB): 24576
Available CPU cores: 8
Binaries:
Node: 20.13.1
npm: 10.5.2
Yarn: N/A
pnpm: 9.1.1
Relevant Packages:
next: 15.0.2 // Latest available version is detected (15.0.2).
eslint-config-next: N/A
react: 19.0.0-rc-02c0e824-20241028
react-dom: 19.0.0-rc-02c0e824-20241028
typescript: N/A
Next.js Config:
output: N/A
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Bug.jsx reproduction and follow the listed steps using window.history.replaceState(), searchParams, and router.refresh(). Trace the navigation handling involved; done means a native replaceState update synchronizes with the Router, triggers the searchParams effect, and remains correct after refresh.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs, react
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100