Skip to content

[labs/ssr] A way for client code to check if running in server (isSsr) #3158

Closed

Description

@augustjk

Which package is this a feature request for?

Lit Core (lit / lit-html / lit-element / reactive-element), SSR (@lit-labs/ssr)

Description

It would be useful for lit to provide a way to detect if code is running in the server like isSsr so it can be utilized when authoring components to intentionally skip, or provide alternatives for, code that utilizes browser DOM APIs or otherwise are incompatible with SSR.

This is a better alternative to adding no-op DOM shims to alleviate errors during SSR.

Idea for implementation would be to utilize conditional exports to provide a module that will only be available/truthy in node.

cc @aomarks

Alternatives and Workarounds

if (typeof process !== 'undefined'), if(typeof window === 'undefined') 😬 , optional chaining, or relying on no-op DOM shims.

Activity

  1. moved this to 📋 Triaged in Lit Project Boardon Jul 21, 2022
  2. changed the title [-][core & ssr] A way for client code to check if running in server (isSsr)[/-] [+][labs/ssr] A way for client code to check if running in server (isSsr)[/+] on Jul 22, 2022
  3. augustjk commented on Sep 28, 2022

    @augustjk
    MemberAuthor

    We're looking at calling this isServer instead and making it an export from lit-html, re-exported from lit.

  4. moved this from 📋 Triaged to 🤔 In Review in Lit Project Boardon Sep 29, 2022
  5. Repository owner moved this from 🤔 In Review to ✅ Done in Lit Project Boardon Sep 29, 2022
  6. augustjk commented on Oct 5, 2022

    @augustjk
    MemberAuthor

    Released now in [email protected]!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions