-
Notifications
You must be signed in to change notification settings - Fork 939
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
[labs/ssr] Lit SSR doesn't work in Cloudflare Workers #3907
Comments
Darn it, I think this is a duplicate of #1983. Sorry about it I'll make a comment there instead. |
There might be some overlap but I think it's valid to keep this a separate issue from #1983 which asks for Service Worker rendering (in the browser) versus handling non-browser worker/edge environments. My biggest hesitation about adding something like this is we ourselves don't have any testing for whether our Node build actually works properly in these environments. We'd have to dig through our dependencies to make sure they don't require any Node specific things. We probably want to limit built-in APIs to these https://common-min-api.proposal.wintercg.org/. We do have an import of lit/packages/lit-html/src/experimental-hydrate.ts Lines 17 to 18 in 440890b
but this actually might be unneeded as the hydrate function is always meant to be run in the client. That module is being removed from lit-html for v3 anyway.
Another question is whether |
Thanks. Yeah while investigating this, I didn't really check if all the node outputs support workers, just that some manual testing showed that it somewhat works. We could run Re
|
We would be very interested in this. For now, we are having to switch everything over to And happy to help or test as needed. |
Which package(s) are affected?
Lit Core (lit / lit-html / lit-element / reactive-element), SSR (@lit-labs/ssr)
Description
Lit SSR doesn't work in Cloudflare Workers as they rely on the "workerd", "worker", "browser" export conditions for bundling with esbuild. In which case, the
lit-html
and@lit/reactive-element
packages are bundled using thebrowser
condition.But because those two packages uses
window
in thebrowser
condition (which is fair), it doesn't work in Cloudflare. We've found that using thenode
condition works since they don't seem to use actual Node-specific APIs.Related withastro/astro#6915. We're fixing Astro's Lit + Cloudflare compatibility.
Reproduction
https://github.com/bluwy/cloudflare-lit-ssr-repro
The repo readme has some extra information of how to debug and patch it.
Workaround
Adding the "worker" condition that's an exact copy of the "node" condition to the aforementioned two packages fixes it.
The repro has a patch script to work around it.
Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
@lit-labs/ssr
-3.1.2
,lit
-2.7.4
Browser/OS/Node environment
(I don't think these are related, but)
OS: macos 13.3
node: 16.19.1
npm: 6.19.3
The text was updated successfully, but these errors were encountered: