-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
57 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 25 additions & 22 deletions
47
react-server-dom-vite-example/src/utils/client-reference.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
export function resolveClientReference(reference: [string]) { | ||
// console.log("[debug:resolveClientReference]", { reference }) | ||
const [id, name] = reference[0].split("#"); | ||
let mod: Record<string, unknown>; | ||
return { | ||
async preload() { | ||
// console.log("[debug:preload]", { id, name}) | ||
if (import.meta.env.DEV) { | ||
mod ??= await import(/* @vite-ignore */ id); | ||
} else { | ||
const { default: references } = await import( | ||
"virtual:build-client-references" | ||
); | ||
mod ??= await references[id](); | ||
} | ||
}, | ||
get() { | ||
// console.log("[debug:get]", { id, name }) | ||
return mod[name]; | ||
}, | ||
}; | ||
} | ||
import type { ClientReferenceManifest } from "../types"; | ||
|
||
export const clientReferenceManifest: ClientReferenceManifest = { | ||
resolveClientReference(reference: string) { | ||
const [id, name] = reference.split("#"); | ||
let resolved: unknown; | ||
return { | ||
async preload() { | ||
let mod: Record<string, unknown>; | ||
if (import.meta.env.DEV) { | ||
mod = await import(/* @vite-ignore */ id); | ||
} else { | ||
const references = await import( | ||
"virtual:build-client-references" as string | ||
); | ||
mod = references.default[id](); | ||
} | ||
resolved = mod[name]; | ||
}, | ||
get() { | ||
return resolved; | ||
}, | ||
}; | ||
}, | ||
}; |