-
Notifications
You must be signed in to change notification settings - Fork 903
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 component was rendered twice event without passing arguments #4472
Comments
I suspect you're missing the Make sure that script is added before your This ensures that on first update, lit element won't create a new shadowroot with content if it detects an existing shadowroot due to the declarative shadow dom having been parsed. |
I added that right now and it stills not working import {render} from '@lit-labs/ssr';
import {
collectResultSync,
} from '@lit-labs/ssr/lib/render-result.js';
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
import '@lit-labs/ssr-client/lit-element-hydrate-support.js';
import {html} from 'lit';
import { Elysia } from 'elysia'
const cache = {}
async function renderIndex({body}) {
if (body && body.html === undefined) {
return {message: 'body is empty', code: 'no-body'}
}
if (body && body.html === undefined) {
return {message: 'html is required', code: 'no-html'}
}
if (body && body.dependencies === undefined) {
return {message: 'dependencies is required', code: 'no-dependencies'}
}
const pending: Promise<any>[] = []
for (let dep of body.dependencies) {
if (cache[dep] === undefined) {
const module = import(dep)
cache[dep] = module
pending.push(module)
}
}
await Promise.all(pending)
const template = html`${unsafeHTML(body.html)}`;
const ssrResult = render(template, { deferHydration: true });
return {html: collectResultSync(ssrResult)}
}
new Elysia()
.post('/', renderIndex)
.get('/test', () => ({status: 200, body: 'test'}))
.listen(3000) |
It needs to be added in the client code, not the server code. |
Thanks @augustjk this was fixed but I think these steps must be placed here https://www.npmjs.com/package/@lit-labs/ssr , I thought that fixture is included without include anything else I thought I made an API rest decoupled that should be used as a lambda function or a microservice, are some of you interested in this? some teams still have issues with the modularity in their backend when they need to render HTML. I got fix how to do it yesterday |
We do have it in the README, https://www.npmjs.com/package/@lit-labs/ssr#:~:text=To%20hydrate%20LitElement%20shadow%20roots%2C%20load%20the%20%40lit%2Dlabs/ssr%2Dclient/lit%2Delement%2Dhydrate%2Dsupport.js%20module, but it is hard to find so perhaps we can emphasize that more. Thanks for the callout! I think there certainly is interest in doing SSR in serverless functions or edge workers (see #3907). I'm sure people can benefit from any findings you're able to share. We have a great community on discord (https://lit.dev/discord) or https://github.com/lit/lit/discussions is a good place for general discussion on github too. |
Well I published a new discussion to show what I have #4475 |
I'll close this issue as completed for adding the hydrate support module. Thanks for opening the discussion on SSR in non-JS environments! |
Which package(s) are affected?
Lit Core (lit / lit-html / lit-element / reactive-element), SSR (@lit-labs/ssr)
Description
My web components is rendering twice even without arguments, I read that if the arguments changed before it was rendered this should happens. Only a button is reactive. The following example is weird because I'm building SSR to an unsupported language
Reproduction
The web version was processed with
bun build components/*.ts components/vl-link.ts --outdir=dist/components --minify --splitting --target=b rowser --watch
This component is rendering twice
Input
The input to SSR was
(?s)<body.*?>(.*?)<\/body>
This code with/without
{ deferHydration: true }
does not workOutput
The button was rendered twice
Workaround
I have not found a workaround
Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
lit@3.1.0 and @lit-labs/ssr-client@1.1.5
Browser/OS/Node environment
Opera One(version: 106.0.4998.19)
Linux archlinux 6.6.8-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Thu, 21 Dec 2023 19:00:41 +0000 x86_64 GNU/Linux
bun 1.0.20
The text was updated successfully, but these errors were encountered: