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

Enhancing SSR Compatibility #810

Open
leventozen opened this issue Mar 8, 2024 · 1 comment
Open

Enhancing SSR Compatibility #810

leventozen opened this issue Mar 8, 2024 · 1 comment

Comments

@leventozen
Copy link
Member

We've been utilizing a pattern for generating React components from our lit framework, aimed at encapsulating custom elements. This approach dynamically imports components using React.lazy and waits for the custom element definition using customElements.whenDefined. Here's a snippet for context:

const source = `
  ${jsDoc}
  export const ${componentName} = React.lazy(() =>
    customElements.whenDefined('${fileName}').then(() => ({
      default: createComponent({
        react: React,
        displayName: "${componentName}",
        tagName: "${fileName}",
        elementClass: customElements.get("${fileName}") as Constructor<${componentName}>,
        events: {
          ${eventNames}
        },
      })
    }))
  );
`;

While this pattern works well in client-side environments, we've encountered issues when integrating with server-side rendering (SSR) frameworks, such as Next.js. The reliance on customElements.whenDefined and dynamic imports via React.lazy poses challenges in SSR contexts, leading to rendering issues or failures when attempting to prerender these components.

@erbilnas
Copy link
Collaborator

Forward from #334 : We can use Lit's SSR support, but this is experimental and may cost us highly: https://lit.dev/docs/ssr/overview/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants