ブラウザバック体験で見るNext.js
ブラウザバック体験で見るNext.js
Theme:
Browser back experience
and Next.js
Browser back is one of the most important web browsing experiences for users.
Back should be quick; users don't expect data to have changed much.However, most applications don’t care about browser back / forward restoration.
IMO, Next.js would be better to implement the below features for the browser back experience.
next/router is easy to integrate with a global state management system such as Redux, Recoil, etc.Scroll restoration has been implemented already behind the experimental flag.
// next.config.js const nextConfig = { // ... experimental: { scrollRestoration: true, }, } module.exports = nextConfig// next.config.js const nextConfig = { // ... experimental: { scrollRestoration: true, }, } module.exports = nextConfig
fix: Scroll restoration bug caused by idx reset to 0 on reload.
https://github.com/vercel/next.js/pull/36861

詳細な解説はzennにまとめてあるので、そちらをご参照ください。
https://zenn.dev/akfm/articles/next-js-scroll-restore

Unfortunately, we cannot sync our UI state with next/router changed using public API.
history.state.next/router, the history key is included in history.state but it is not opened. We have created a new library, recoil-sync-next!(and I helped a little with that.)
This lib could be better to improve the browser back experience.
export const counter = atom<number>({ key: 'counterState', default: 0, effects: [ syncEffect({ storeKey: 'ui-state', refine: number(), }), ], })export const counter = atom<number>({ key: 'counterState', default: 0, effects: [ syncEffect({ storeKey: 'ui-state', refine: number(), }), ], })
これも、詳細な解説はzennにまとめてあるのでそちらをご参照ください。
https://zenn.dev/akfm/articles/recoi-sync-next

First of all, thanks for having scrollRestoration.
app directory could also support scrollRestoration.next/router would expose the key as with the Navigation API.useNextState?) implemented.