Skip to content

Commit e95cc89

Browse files
committed
add search to cache key
1 parent 41dae30 commit e95cc89

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

example/pages/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Link, navigate, useLink } from "bun-react-ssr/router";
1+
import { Link } from "bun-react-ssr/router";
22

33
export default function Index() {
4-
return <Link href="/test">index</Link>;
4+
return <Link href="/test?test">index</Link>;
55
}

hydrate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Suspense } from "react";
22
import { hydrateRoot } from "react-dom/client";
33
import { RouterHost } from "./router";
4-
import { ServerSideProps } from "./types";
54
import { getRouteMatcher } from "./router/utils/get-route-matcher";
5+
import { ServerSideProps } from "./types";
66

77
const globalX = globalThis as unknown as {
88
__PAGES_DIR__: string;
@@ -16,7 +16,7 @@ const match = getRouteMatcher(globalX.__ROUTES__);
1616
export async function hydrate(
1717
Shell: React.ComponentType<{ children: React.ReactElement } & ServerSideProps>
1818
) {
19-
const matched = match(globalX.__INITIAL_ROUTE__)!;
19+
const matched = match(globalX.__INITIAL_ROUTE__.split("?")[0])!;
2020
const Initial = await import(matched.value);
2121
return hydrateRoot(
2222
document,

index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class StaticRouters {
4747
bootstrapModules?: string[];
4848
}
4949
) {
50-
const { pathname } = new URL(request.url);
50+
const { pathname, search } = new URL(request.url);
5151
const staticResponse = await serveFromDir({
5252
directory: this.buildDir,
5353
path: pathname,
@@ -92,7 +92,7 @@ export class StaticRouters {
9292
bootstrapScriptContent: [
9393
preloadScript,
9494
`__PAGES_DIR__=${JSON.stringify(this.pageDir)}`,
95-
`__INITIAL_ROUTE__=${JSON.stringify(serverSide.pathname)}`,
95+
`__INITIAL_ROUTE__=${JSON.stringify(serverSide.pathname + search)}`,
9696
`__ROUTES__=${this.#routes_dump}`,
9797
`__SERVERSIDE_PROPS__=${stringified}`,
9898
]

router/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const RouterHost = ({
4848
Shell: React.ComponentType<{ children: React.ReactElement }>;
4949
}) => {
5050
const pathname = useLocationProperty(
51-
() => location.pathname,
51+
() => location.pathname + location.search,
5252
() => globalX.__INITIAL_ROUTE__
5353
);
5454
const [current, setCurrent] = useState(children);
@@ -58,7 +58,7 @@ export const RouterHost = ({
5858
(async () => {
5959
const currentVersion = ++version.current;
6060
const [module, props] = await Promise.all([
61-
import(match(pathname)!.value),
61+
import(match(pathname.split("?")[0])!.value),
6262
cachedFetchServerSideProps(pathname),
6363
]);
6464
if (currentVersion === version.current) {

0 commit comments

Comments
 (0)