Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: css modules #446

Merged
merged 3 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/waku/src/lib/plugins/vite-plugin-rsc-hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,32 @@ async function generateInitialScripts(
}

const scripts: HtmlTagDescriptor[] = [];
let injectedBlockingViteClient = false;

for (const result of sourceSet) {
// CSS modules do not support result.source (empty) since ssr-transforming them gives the css keys
// and client-transforming them gives the script tag for injecting them.
if (result.id.endsWith('.module.css')) {
if (!injectedBlockingViteClient) {
// since we use the client-transformed script tag, we need to avoid FOUC by parse-blocking the vite client that the script imports
// this way we make sure to run the CSS modules script tag before everything
// blocking this way is not ideal but it works. It should be revisited.
scripts.push({
tag: 'script',
attrs: { type: 'module', blocking: 'render', src: '/@vite/client' },
injectTo: 'head-prepend',
});
injectedBlockingViteClient = true;
}
scripts.push({
tag: 'script',
// tried render blocking this script tag by data url imports but it gives `/@vite/client: Invalid relative url or base scheme isn't hierarchical.` which could not find a way to fix.
attrs: { type: 'module', 'waku-module-id': result.id },
children: result.code,
injectTo: 'head-prepend',
});
continue;
}
scripts.push({
tag: 'style',
attrs: { type: 'text/css', 'waku-module-id': result.id },
Expand Down
39 changes: 37 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading