Repository navigation
[labs/ssr-dom-shim] Implement limited shim for CSSStyleSheet and CSS loader for Node.js - #4879
Conversation
… CSS loader for Node.js
🦋 Changeset detectedLatest commit: 2ab5121 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This seems expected. We can't rely on import ordering because while eval happens in order, fetching and parsing happen in parallel.
Not by default, it should be installed with the other DOM globals.
What do you mean with these last two points? |
How to provide/integrate the loader. I think you answered this by suggesting to add it to
Should usage of |
|
I changed the terminology from |
|
Hello @thescientist13 |
|
Hey @kyubisation thanks so much for all your great work on this!
It seems like it would, but I haven't had a case to use the Inferring from the changes in this PR though, would I just simply need to add these lines to the top of my script in the repro repo? // add these lines
import '@lit-labs/ssr-dom-shim/css-hook.js';
import {installWindowOnGlobal} from './dom-shim.js';
installWindowOnGlobal();
// rest of the code as normal
import fs from 'node:fs/promises';
import { html } from 'lit';
import { render } from '@lit-labs/ssr';
import { collectResult } from '@lit-labs/ssr/lib/render-result.js';
import './components/greeting/greeting.js';
//...
Yeah, I think that would be helpful for composition purposes, so consumers can cherry-pick whatever parts they want of this implementation, which I think is really nice for folks building meta-frameworks around Lit / Lit+SSR. Left some other thoughts in the PR, feel free to take or leave them. |
| "types": "./index.d.ts", | ||
| "default": "./index.js" | ||
| }, | ||
| "./css-hook.js": { |
There was a problem hiding this comment.
Just a heads up that there is an option to set an export condition
https://nodejs.org/api/module.html#enabling
Where some-package has an "exports" field defining the
/registerexport to map to a file that callsregister(), like the following register-hooks.js example.
edit: though maybe this is what you indicated would be the follow up PR?
There was a problem hiding this comment.
edit: though maybe this is what you indicated would be the follow up PR?
Yes, basically. But to be able to use it from @lit-labs/ssr I already need a specific exports entry in @lit-labs/ssr-dom-shim. This also allows it to be used directly from this package, if so desired.
No, that would still break, as the imports to the hook and the component (which in turn imports the css file) are on the same "level". |
Ah, OK. I'm reviewing the README a bit with more your recommendations and think I get it now. I assume this is because of the requirement to exclude |
|
@justinfagnani @thescientist13 I implemented a check whether the runtime environment support importing CSS files directly and whether hooks can be registered. Feel free to provide feedback, if you have concerns. |
thescientist13
left a comment
There was a problem hiding this comment.
Happy to test this out when it is ready / published 👍
…loader for Node.js (lit#4879)
This PR adds a shim for CSSStyleSheet (and associated classes) and a CSS loader hook for Node.js.
Limitation
The CSS loader cannot be registered synchronously (i.e. if you import LitElement/the shim and a .css file from the same file, it will break). Due to this the loader needs to be registered via
--import @lit-labs/ssr-dom-shim/css-loader.jsvia Node.js CLI or imported before dynamically importing components.Closes #4862
Relates to #2631