@redwoodjs/sdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
21 lines (20 loc) • 823 B
JavaScript
import memoize from "lodash/memoize";
export const loadModule = memoize(async (id) => {
if (import.meta.env.DEV && !process.env.PREVIEW) {
return await import(/* @vite-ignore */ id);
}
else {
const { useClientLookup } = await import("virtual:use-client-lookup");
const moduleFn = useClientLookup[id];
if (!moduleFn) {
throw new Error(`No module found for '${id}' in module lookup for "use client" directive`);
}
return await moduleFn();
}
});
// context(justinvdm, 2 Dec 2024): re memoize(): React relies on the same promise instance being returned for the same id
export const clientWebpackRequire = memoize(async (id) => {
const [file, name] = id.split("#");
const module = await loadModule(file);
return { [id]: module[name] };
});