CSS Modules classes are compiled as dynamic/reactive variables rather than static strings (Optimization)
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- typescript, vite
- Domain
- build-system, frontend, performance
Research direction
Start by tracing the Solid Babel plugin and Vite CSS Modules processing order; the issue provides a custom Vite plugin as a comparison point. Determine whether the processing-order change belongs in this repository or Vite, and define completion as CSS Module class strings being compiled as static, non-reactive DOM text without the workaround.
Written by the indexing model from the issue text.
Description
@ryansolid Just following up on the issue we discussed during your Friday stream.
CSS Module classes are substituted for static strings by Vite AFTER the Solid babel plugin runs, so the CSS class strings are not compiled into static text directly in the DOM strings. This has a considerable performance effect because it breaks up long strings that would otherwise be inserted into the DOM at once statically.
This can be alleviated slightly with a custom Vite plugin like this one, which adds @once to at least compile these without reactivity:
{
name: 'vite-plugin-optimize-solid-css-modules',
enforce: 'pre',
transform: {
handler: code => ({
code: code.replace(/class=\{([a-zA-Z '"`[\].-]+|(?:`(?:\$\{[a-zA-Z '"`[\].-]+\}\s*)+)`)\}/g, 'class={/*@once*/$1}'),
map: null,
}),
filter: { id: /\.[mc]?[jt]sx$/ },
},
}
But without a modification to the order that CSS modules are processed, getting CSS modules to match the performance of plain CSS won’t be possible. I’ve taken a stab at fixing it myself, but the fix may need to be contributed to Vite. Needs some further investigation.
- Dominant language
- TypeScript
- Stars
- 520
- Forks
- 70
- Avg merge
- 23h 35m
- Merged PRs (30d)
- 39
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from solidjs/solid-vite-plugin
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
solidjs/solid-vite-plugin#205 · 1 comment · 2 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
solidjs/solid-vite-plugin#369 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
solidjs/solid-vite-plugin#328 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
solidjs/solid-vite-plugin#308 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
solidjs/solid-vite-plugin#262 · 2 comments ·
All issues in solidjs/solid-vite-plugin
Similar issues
-
S: triage
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
fix(errors): EHOSTUNREACH from a happy-eyeballs connect is reported as a resolver error (STAMP-80) Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
snapshot-labs/stamp#666 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
GauravKarakoti/SecureFlow#1070 · 1 comment ·
-
feature:Languages/Translations good first issue ready Web
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
digitalfabrik/integreat-app#4394 ·