-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7b5ad37
update lit-ssr dependency
e111077 b6df023
delete unnecessary lit shim checks
e111077 c372701
delete another unused lit shim feature
e111077 a4450db
fix sass build
e111077 2aae3e6
bump lit and polyfill versions to match ssr req
e111077 842d28e
shim HTMLElement in test
e111077 96bb425
remove lit global shim workarounds
e111077 32ccf04
re-shim Astro's ce.define
e111077 c151088
remove fix window test and shim HTML Element
e111077 7d518b3
Update .changeset/gold-windows-fly.md
e111077 afd72ff
fix window check test
e111077 a533b98
Merge branch 'update-lit-ssr' of github.com:e111077/astro into update…
e111077 4b9a03e
implement suggestoins
e111077 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@astrojs/lit': major | ||
--- | ||
|
||
Update to use `@lit-labs/ssr@^3` | ||
**[BREAKING]** DOM shim required for Lit SSR has been greatly reduced. `window`, `document`, and other objects are no longer available in global. Most SSR-ready component code should not be affected but, if so, they can be fixed with optional chaining or by using the `isServer` environment checker from the `lit` package. See [lit.dev docs on authoring components for SSR].(https://lit.dev/docs/ssr/authoring/#browser-only-code) | ||
**[BREAKING]** Adds compatibility with `[email protected]` hydration behavior. Do not update if you're using `[email protected]` or lower. | ||
Includes support for template[shadowrootmode] support. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
import { installWindowOnGlobal } from '@lit-labs/ssr/lib/dom-shim.js'; | ||
import { customElements as litCE, HTMLElement as litShimHTMLElement } from '@lit-labs/ssr-dom-shim'; | ||
|
||
if (typeof fetch === 'function') { | ||
const _fetch = fetch; | ||
installWindowOnGlobal(); | ||
globalThis.fetch = window.fetch = _fetch; | ||
} else { | ||
installWindowOnGlobal(); | ||
// Something at build time injects document.currentScript = undefined instead of | ||
// document.currentScript = null. This causes Sass build to fail because it | ||
// seems to be expecting `=== null`. This set to `undefined` doesn't seem to be | ||
// caused by Lit and only happens at build / test time, but not in dev or | ||
// preview time. | ||
if (globalThis.document) { | ||
document.currentScript = null; | ||
} | ||
|
||
window.global = window; | ||
document.getElementsByTagName = () => []; | ||
// See https://github.com/lit/lit/issues/2393 | ||
document.currentScript = null; | ||
if (globalThis.HTMLElement) { | ||
// Seems Astro's Element shim does nothing when `.setAttribute` is called | ||
// and subsequently `.getAttribute` is called. Causes Lit to not SSR attrs | ||
globalThis.HTMLElement = litShimHTMLElement; | ||
} | ||
|
||
// Astro seems to have a DOM shim and the only real difference that we need out | ||
// of the Lit DOM shim is that the Lit DOM shim reads | ||
// `HTMLElement.observedAttributes` which is meant to trigger | ||
// `ReactiveElement.finalize()`. So this is the only thing we will re-shim since | ||
// Lit will try to respect other global DOM shims. | ||
globalThis.customElements = litCE; | ||
|
||
const litCeDefine = customElements.define; | ||
|
||
const ceDefine = customElements.define; | ||
// We need to patch customElements.define to keep track of the tagName on the | ||
// class itself so that we can transform JSX custom element class definintion to | ||
// a DSD string on the server, because there is no way to get the tagName from a | ||
// CE class otherwise. Not an issue on client:only because the browser supports | ||
// appending a class instance directly to the DOM. | ||
customElements.define = function (tagName, Ctr) { | ||
Ctr[Symbol.for('tagName')] = tagName; | ||
return ceDefine.call(this, tagName, Ctr); | ||
return litCeDefine.call(this, tagName, Ctr); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andHTMLElement
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