Comments (2)
yep, it's related to that, even updating query params messes it up..I had to come up with a hack to work with search params
it only works with search params though, and I didn't implement the scroll
flag cause I don't need it
"use client";
import { useSyncExternalStore } from "react";
const isServer = typeof window === "undefined";
class History {
listeners = new Set<() => void>();
constructor() {
if (isServer) {
return;
}
window.addEventListener("popstate", () => {
this.emit();
});
}
emit() {
this.listeners.forEach((cb) => cb());
}
subscribe = (cb: () => void) => {
this.listeners.add(cb);
return () => {
this.listeners.delete(cb);
};
};
push = (url: string, _: { scroll: boolean }) => {
if (isServer) {
return;
}
window.history.pushState({}, "", url);
this.emit();
};
replace = (url: string, _: { scroll: boolean }) => {
if (isServer) {
return;
}
window.history.replaceState({}, "", url);
this.emit();
};
getSnapshot = () => {
return new URL(window.location.href).searchParams.toString();
};
}
const customHistory = new History();
export const _useRouter = () => {
const searchParams = useSyncExternalStore(
customHistory.subscribe,
customHistory.getSnapshot,
() => ""
);
return {
searchParams,
push: (url: string, options: { scroll: boolean }) => {
customHistory.push(url, options);
},
replace: (url: string, options: { scroll: boolean }) => {
customHistory.replace(url, options);
},
};
};
from awesome-fastapi-projects.
@julia-script Thanks for the input!
I believe a custom history could be a solution for that.
I see there is also some progress on vercel/next.js#48110, so maybe a fix will be delivered shortly in some future release.
I have recently found a package: https://github.com/47ng/next-usequerystate
What caught my eye is: https://github.com/47ng/next-usequerystate#shallow
Note: the app router doesn't vercel/next.js#48110 have this capability natively, but next-usequerystate does, by bypassing the router on shallow updates.
So, I think using this package until a proper fix is introduced in Next.js could be worth trying.
from awesome-fastapi-projects.
Related Issues (17)
- Links Updation HOT 1
- Link to 2020_slowdelivery_take is not working HOT 2
- Serious need for an update HOT 4
- Looking for maintainers HOT 14
- error while running your project HOT 1
- Add CONTRIBUTING.md HOT 1
- Maintenance
- Make the repositories sorted by stars (descending) by default
- Improve pagination
- Improve the mobile UI
- Statistics
- Dark mode
- Standardize changelog and releasing
- Improve dependencies parsing performance
- Create curator bot
- Deadlink: the project ExpenseAPI HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awesome-fastapi-projects.