Skip to content

Commit

Permalink
fix: load module for actions (#841)
Browse files Browse the repository at this point in the history
oh, boy, this is huge.

There must be huge room for improvement with `vite-plugin-rsc-rsdw.ts`.
We should never use `import` on the server in PRD.
  • Loading branch information
dai-shi authored Aug 20, 2024
1 parent e90e239 commit 036559f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/waku/src/lib/plugins/vite-plugin-rsc-entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function loadModule(id) {
default: throw new Error('Cannot find module: ' + id);
}
}
globalThis.__WAKU_SERVER_HACK_IMPORT__ = loadModule;
`;
let entriesFile = '';
return {
Expand Down
11 changes: 4 additions & 7 deletions packages/waku/src/lib/renderers/rsc-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,10 @@ export async function renderRsc(
{
get(_target, encodedId: string) {
const [fileId, name] = encodedId.split('#') as [string, string];
const id = filePathToFileURL(fileId);
if (fileId.startsWith('@id/assets/')) {
const id = '.' + fileId.slice('@id'.length);
return { id, chunks: [id], name, async: true };
} else {
return { id, chunks: [id], name, async: true };
}
const id = fileId.startsWith('@id/')
? fileId.slice('@id/'.length)
: filePathToFileURL(fileId);
return { id, chunks: [id], name, async: true };
},
},
);
Expand Down

0 comments on commit 036559f

Please sign in to comment.