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] Investigate interactions with minified or unminified lit-html #4527
Comments
Hello @AndrewJakubowicz! I hit this issue when I'm trying to use the app router in a Next 14 app. I have a library where we've enabled SSR, and thus far it's been working well when utilizing the components in a Next app with pages router. But as soon as I start using the app router and try to view the page source, I get this issue: I've attached a simplified reproduction of the issue in the form of two repositories. The Is there any work being done on this issue right now? Our organization is going to be enabling the app router for many of our applications soon, and we'd like to continue to have SSR support for those who want to use Next's app router. Please let me know if you need any more info or if I can help keep this issue moving. I truly appreciate all the Lit team is doing to enable SSR! design-system-ssr.zip cc @augustjk |
@keisha-rw this issue might be related #3845 (comment) Also the lit nextjs plugin currently won't deeply SSR custom elements with the app router as we're not targeting for those files when injecting our patches. I've been meaning to address this but it'll require some clear documentation on limitations. It's looking like deeply server rendering custom elements producing declarative shadow DOM won't work when used within React Server Components. See #3657 |
Hey @augustjk! Thanks for taking a look! I already had the fix to force dev via node options (I am using it with our pages router implementation), and that didn't seem to do the trick in this instance. I started looking at the different Lit libraries that my next app was pulling in, and I did have What's interesting is that if I removed the FWIW, I'm ok with using client components for a bit (since they still do render on the server) until you guys can get the declarative shadow dom deeply rendering in RSCs. I'd just like my consumers to be able to pick if they want to use the pages or the app router (or both). Fully supporting RSCs can come later for us! |
Using I'm going to try and work on plugin support for app router and v14 into the nextjs plugin soon. |
You are truly a gem, @augustjk! 🌟 Thank you for that. My library sets the |
Hey @augustjk! 👋 I've been doing more investigation on this lately and it seems to be working at times, but occasionally I still get this error when using the app router, even with a manual install of That aside, do you think your monkey-patching updates in this PR #4575 will fix this issue? If so, do you have any idea on when that PR might merge and be released? We'd like to start rolling out SSR with our components in applications that use the app router. As always, thanks for your work on this! |
I don't think #4575 would fix this particular problem as it doesn't change anything about how user code is imported. When you say occasionally, is it the same app that sometimes works and sometimes doesn't? Or have you been able to isolate something that consistently causes it like inclusion of particular components? Does the error only happen when you run it in dev mode? If forcing condition doesn't fix, another source of the discrepancy I can think of is there may be pre-bundled code that includes production version of Lit. I think ideally we'd want to just be able to avoid this whole thing by making things work across both dev and prod builds, but I don't know if that's really feasible without a hard-code of internal minified method names which seems bad for maintainability. |
So now it seems I'm getting this message rather consistently. I'll keep poking around to try to get a better idea of when/why this is popping up again, but I still can't quite get a handle on what's causing it to show up. Given that the message is coming from I also noticed that I'm getting Please let me know if you have any ideas for what I can try to debug to get to the bottom of this! |
Thanks for the additional info! The deletion of
To be clear, this does not happen if you do a production build? |
I think you're onto something with the idea of looking into how Next builds and loads code per route, because when I use the same code for our lib in a Next 13 app with pages router, I don't see this error at all. The rest of my team has been testing our SSR implementation of our components library in the Next 13/pages router as well and no one has hit this issue there. So I'm pretty confident it's not that we actually have a bundled production version of Lit within our code or I'd think we'd be seeing this issue in our pages router app too. I did create a minimal repro in #4527 (comment) if that helps! I haven't put this through its paces beyond local development yet, but I can see what happens when I run a production build. I'll try to fake that out locally because we don't have a proper workflow set up with the Next 14/app router app at the moment. I'll keep you posted as I continue working on this, but in the meantime, I appreciate any insights you may have! Thanks a ton. |
I got back to this today and tried to run a production build, but given that this is Next 14, I hit the issue mentioned here: #3657 (comment) and it won't build. So unfortunately I'll need the fix for Next 14 to merge before I can test this out with a production build. |
@keisha-rw sorry for the delay. The Next 14 support and fix to those errors have now been released. I don't think it would do anything for the dev/prod mixup, but you should be able to test it. |
@augustjk Thank you!! 🎉 I'll take a look at this hopefully in the next week or two and see how it's working for us. In the meantime, I created a client-side only bundle of our library for Next 14/app router users, so I'm excited to see if we can enable SSR functionality for them! I'll keep you posted. |
Which package(s) are affected?
SSR (@lit-labs/ssr)
Description
Issue was raised by Justin here: #4515 (comment)
Because ssr depends on its own
lit-html
, there is the possibility that the version oflit-html
that ssr imports is minified, while the templates/directives being SSR'd are not minified, or vice-versa. E.g. if a library being SSR'd has its own bundled Lit.Reproduction
No repro, the objective of this issue is to potentially write a repro PR, or add testing.
The text was updated successfully, but these errors were encountered: