URL hash for state unpredictable in app and page dir #49601
Labels
area: app
App directory (appDir: true)
bug
Issue was opened via the bug report template.
Navigation
Related to Next.js linking (e.g., <Link>) and navigation.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:58 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6020 Binaries: Node: 18.14.0 npm: 9.3.1 Yarn: 1.22.19 pnpm: 8.4.0 Relevant packages: next: 13.4.2-canary.0 eslint-config-next: 13.2.4 react: 18.2.0 react-dom: 18.2.0 typescript: 4.9.5
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue
https://github.com/lloydrichards/DeepLinks-in-Nextjs
To Reproduce
Post
linkname
andtag
are found in state, but tag is not in URLPost: Sport
linkname
andtag
are found as before in state, but tag in the url is differentPost: [ tag ]
linkname
andtag
are found as before in state, and tag in url is correctname
andtag
are not found in state, url hash is now missingPost: [ tag ]
linkDescribe the Bug
Have been trying to use Jotai to reproduce deeplink states in the URL so the configuration of a dashboard can be shared via URL. This was working previously in Next12 and documented in Jotai by tapping into the Router.on() events to sync the state of the atoms with the router.
In 13 this was broken and up until recently I've been waiting for the feature related to hashes in the App Dir Roadmap. With 13.4 there were some improvements to how the hash was loaded using just the atomWithHash() but after some experimenting have found even weirder behaviour when mixing the app and pages directory and trying to create hash states.
In the minimal repo, you can try add a nameAtom (which is held in global state) and a tag which uses the hash and then navigate between the pages. You will see that sometimes the tag is added to the hash, something the hash is replaced manually but the pervious value is found by the atom, and sometimes it is removed all together.
Expected Behavior
For the tag: I would expect that whatever the tag is set as in the url, that this is represented as the value on the page after navigation or page load.
For the name: I would expect the name value to be stored as state across the app and pages directory. And even if the state is lost when navigating to the pages directory, at least when going back to the app directory that the state is restored
Which browser are you using? (if relevant)
Chrome
How are you deploying your application? (if relevant)
Vercel
The text was updated successfully, but these errors were encountered: