Skip to content

Commit 1b82062

Browse files
committed
fix duplicated preload
1 parent 34a742e commit 1b82062

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

hash.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { join, parse } from "node:path";
2+
3+
export function hashremap(input: string, hash: string) {
4+
const parsed = parse(input);
5+
return `${join(parsed.dir, parsed.name)}-${hash}${parsed.ext}`;
6+
}
7+
8+
export function generateHashedName(name: string, hash: Record<string, string>) {
9+
return hash[name] ? hashremap(name, hash[name]) : name;
10+
}

index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { FileSystemRouter, type BunFile } from "bun";
22
import { NJSON } from "next-json";
33
import { readFileSync, statSync } from "node:fs";
4-
import { join, parse, relative } from "node:path";
4+
import { join, relative } from "node:path";
55
import { renderToReadableStream } from "react-dom/server";
66
import { ClientOnlyError } from "./client";
7+
import { hashremap } from "./hash";
78
import { MetaContext, PreloadModule } from "./preload";
89

910
export class StaticRouters {
@@ -225,11 +226,6 @@ function* scanCacheDependencies(
225226
} catch {}
226227
}
227228

228-
function hashremap(input: string, hash: string) {
229-
const parsed = parse(input);
230-
return `${join(parsed.dir, parsed.name)}-${hash}${parsed.ext}`;
231-
}
232-
233229
export class StaticFileCache {
234230
#cache = new Map<string, BunFile>();
235231
constructor(public base: string) {}

preload.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createContext, use } from "react";
22
import { preloadModule, type PreloadModuleOptions } from "react-dom";
3+
import { generateHashedName } from "./hash";
34

45
// @ignore
56
export const MetaContext = createContext<{
@@ -19,10 +20,6 @@ function* walkDependencies(
1920
}
2021
}
2122

22-
function generateHashedName(name: string, hash: Record<string, string>) {
23-
return hash[name] ? `${name}?${hash[name]}` : name;
24-
}
25-
2623
export function PreloadModule({
2724
module,
2825
...options

0 commit comments

Comments
 (0)