Skip to content
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/observers] Prevent failing in SSR #4590

Open
a11delavar opened this issue Mar 22, 2024 · 0 comments · May be fixed by #4591
Open

[labs/observers] Prevent failing in SSR #4590

a11delavar opened this issue Mar 22, 2024 · 0 comments · May be fixed by #4591

Comments

@a11delavar
Copy link

Which package(s) are affected?

Observers (@lit-labs/observers)

Description

All observer controllers crash when used in SSR as their constructors don't count on the fact that the window object is not available in the server environment.

Reproduction

Any component that uses some observer controller will fail in SSR:

@customElement('some-component')
class SomeComponent extends LitElement {
    readonly mutationController = new MutationController(this, {
        config: {
	    subtree: true,
	    characterData: true,
	    childList: true,
        })
}

Workaround

You could just add an inline isServer check and not initialized the controller. Not very ergonomic though!

@customElement('some-component')
class SomeComponent extends LitElement {
-    readonly mutationController = new MutationController(this, {
+    readonly mutationController = isServer ? undefined : new MutationController(this, {
        config: {
	    subtree: true,
	    characterData: true,
	    childList: true,
        })
}

Is this a regression?

No or unsure. This never worked, or I haven't tried before.

Affected versions

All versions

Browser/OS/Node environment

All Node versions

@a11delavar a11delavar linked a pull request Mar 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Triaged
Development

Successfully merging a pull request may close this issue.

1 participant