-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Update lit-ssr dependency #6681
Conversation
🦋 Changeset detectedLatest commit: 4b9a03e The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -8,10 +8,6 @@ const test = testFactory({ | |||
// TODO: configure playwright to handle web component APIs | |||
// https://github.com/microsoft/playwright/issues/14241 | |||
test.describe('Lit components', () => { | |||
test.beforeAll(() => { | |||
delete globalThis.window; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needs to shim the window?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the shims needed for lit are baked into Lit's node build. I just pushed a commit though because we do need to actually re-shim only customElements.define
and HTMLElement
because our baked-in shims in ReactiveElement's node build is forgiving and tries to call anything anyone else has shimmed, but we have a small hack we are relying on so we re-shim that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the readme should be updated
astro/packages/integrations/lit/README.md
Lines 123 to 142 in fc71c3f
### Browser globals | |
The Lit integration's SSR works by adding a few browser global properties to the global environment. Some of the properties it adds includes `window`, `document`, and `location`. | |
These globals *can* interfere with other libraries that might use the existence of these variables to detect that they are running in the browser, when they are actually running in the server. This can cause bugs with these libraries. | |
Because of this, the Lit integration might not be compatible with these types of libraries. One thing that can help is changing the order of integrations when Lit is interfering with other integrations: | |
```diff | |
import { defineConfig } from 'astro/config'; | |
import vue from '@astrojs/vue'; | |
import lit from '@astrojs/lit'; | |
export default defineConfig({ | |
- integrations: [vue(), lit()] | |
+ integrations: [lit(), vue()] | |
}); | |
``` | |
The correct order might be different depending on the underlying cause of the problem. This is not guaranteed to fix every issue however, and some libraries cannot be used if you are using the Lit integration because of this. |
Co-authored-by: Augustine Kim <[email protected]>
@matthewp would also like to note that we have to re-shim HTMLElement because Astro's DOM shim doesn't seem to do anything when you do element.setAttribute('foo', 'bar')
element.setAttribute('baz', 'quux')
element.getAttribute('foo') // bar
element.attributes // ['foo', 'baz'] https://github.com/withastro/astro/blob/main/packages/webapi/src/lib/Element.ts#L25-L32 I wonder WYT about implementing that in Astro? |
You also might want to squash merge this one 🙈 |
Thanks! I'm not sure how we feel about having the DOM shim in long term. Sort of feel like the renderer should bring its own if needed. So I think what you are doing here is fine for now, thanks! |
@augustjk is this ok with you now? can you give your 👍 if you think this is good to merge? |
Looking good, thank you!! |
but waiting for next astro release to contain a fix for latest lit withastro/astro#6670 withastro/astro#6681
but waiting for next astro release to contain a fix for latest lit withastro/astro#6670 withastro/astro#6681
fixes #6670
Changes
lit@^2.7.0
's requirementsTesting
Usual test run – tests updated
Docs
Should not require behavior change