-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update lit-ssr dependency * delete unnecessary lit shim checks * delete another unused lit shim feature * fix sass build * bump lit and polyfill versions to match ssr req * shim HTMLElement in test * remove lit global shim workarounds * re-shim Astro's ce.define * remove fix window test and shim HTML Element * Update .changeset/gold-windows-fly.md Co-authored-by: Augustine Kim <ajk830@gmail.com> * fix window check test * implement suggestoins --------- Co-authored-by: Augustine Kim <ajk830@gmail.com>
- Loading branch information
Showing
13 changed files
with
107 additions
and
82 deletions.
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 `lit@2.7.0` hydration behavior. Do not update if you're using `lit@2.6.1` 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.