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
[ssr] Can't bundle into SSR app because of side-effects #1213
Comments
The problem with fixing the What we're doing in lit-ssr is creating a minimal DOM shim to define the needed APIs: https://github.com/PolymerLabs/lit-ssr/blob/master/src/lib/dom-shim.ts If you don't want to actually run the code you can have an even more minimal shim. |
I'm not using Just to be clear - I'm not actually invoking |
Leaving this open to add a Node importability test per this comment: https://app.zenhub.com/workspaces/polymer-project-5ce5a1fc3c14bf6d63636b62/issues/lit/lit/1214#issuecomment-820668662. |
We've just published some pre-releases for Lit which includes #3156. This change means that Lit should now be importable directly from Node, without crashing, without the need to first load the global DOM shim. You should be able to upgrade with:
Note this won't automatically enable any kind of actual SSR of Lit components out-of-the-box, since that requires specific integration with the framework/renderer -- but it should allow you to import without crashing Node. Also note that this does not automatically globally define any DOM APIs like the global DOM shim does, apart from customElements which is shimmed as a no-op. So if you have any calls like window.addEventListener running at module initialization, that will still error. If you have a chance to check out this pre-release, that would be great, and please comment here to let us know how that works for you! |
The PR mentioned above has made its way to a stable release so closing this as fixed! |
Description
I understand that this project is inherently incompatible with SSR, but this module can literally not be
import
ed into a NextJS project (for example) because you get the following error:This is because of the following lines in
shady-render.ts
:If this could be refactored to be side-effect-free (and not depend on
window
at import-time) then we could do the following without an error:Expected Results
No error thrown by importing the
lit-html
library in an SSR context.Actual Results
An error is thrown by importing the
lit-html
library in an SSR context.Browsers Affected
Not applicable.
The text was updated successfully, but these errors were encountered: