-
Notifications
You must be signed in to change notification settings - Fork 879
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
Refactor shady-render not to do "window" check as side-effect #1214
Conversation
Hello there! What is the state of this one? This really needs to be fixed for SRR to work! |
I agree, in fact I think it's even more critical than that. |
I've checked it out, but the problem is that this doesn't cover everything we'd need to do to make our libraries work in systems that run the code, but don't provide a DOM environment, and it It seems to me like there's a problem with the SSR library if it's running client-side JavaScript and not providing the minimal environment expected. Is there not a way to customize the environment in Next.js to provide some global definitions? |
If you have the vision and motivation to make rendering work in a Node context (or anywhere that
That's my entire point, it's not running the code. By which I mean… Next is not trying to do any rendering with it (because of the |
By importing a library, Next.js is by definition running code. JavaScript modules have top-level statements that run when the module is imported. The problem I have with this approach is that it places the burden of interoperability on client-side modules that are not even intended to be used server-side at the moment. It only fixes one reference to There is a lot of client-side code out there that one could reasonably want to import from a Next.js project. There must be a more generic and scalable way to handle these situations. It looks like this is their intended escape hatch: https://nextjs.org/docs/advanced-features/dynamic-import import dynamic from 'next/dynamic';
const ClientComponent = dynamic(() => import('../components/component-that-uses-lit-html.js'));
function App() {
return (
<div>
<ClientComponent />
</div>
);
} Then |
Yes, I'm well aware of this – but now you're using semantics to try and justify your point, and it's a strawman argument. The PR description already mentions that the issue in question is that the module has window dependent "side effects". I'd like to point out once again that this is not a NextJS-specific issue, but you're trying to "solve" the problem on my behalf with NextJS-specific workarounds, which I've already done. My problem though, is that I've actually published an internal web-component library, rather than, say, a React component library because of framework/platform agnosticism. And yes, after inspecting other parts of this library (and |
@ryami333 sorry, I didn't mean to leave this hanging so long. We're about to release lit-html 2.0, so I'd rather see any fixes related to Node go there. With the new monorepo, we have several tests running in Node already and it's not a big change to add a new one to ensure that modules remain importable there. |
Fixes this issue. In short, this library can not be used in SSR frameworks like NextJS because there is a side-effect in
shady-render
which reads from thewindow
variable, which would be undefined in an SSR context. This is a small refactor to allow users to do the following without a type error: