-
Notifications
You must be signed in to change notification settings - Fork 939
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/Core] Add @lit-labs/ssr-dom-shim package #3522
Conversation
🦋 Changeset detectedLatest commit: 4f01ca2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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 |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultslit-element-list
render
update
update-reflect
lit-html-kitchen-sink
render
update
nop-update
lit-html-repeat
render
update
lit-html-template-heavy
render
update
reactive-element-list
render
update
update-reflect
|
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 is great! Some comments below.
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.
Comments addressed.
Also addressed two comments from @kevinpschaaf that were made in an in-person conversation:
-
reactive-element.js
in Node now falls back toglobalThis.HTMLElement
if one has been defined, which matches the behavior we had before, and allows users to use alternative DOM shims if they want. -
The existing
getWindow
function from the SSR package now behaves like it did before, in that it returns anew CustomElementRegistry
for each object, instead of using a global singleton. This is important for VM modules that are usinggetWindow
, since otherwise there would be a shared CE registry between different VM render contexts.
06a9dd0
to
68559e0
Compare
68559e0
to
b7dc1b9
Compare
Ah, seeing failures relating to code that looks at the TypeScript AST. Now I remember why we did the weird temporary-global-assignment trick previously. Though that won't work here, because of the shadowing we have due to the import. Will need to investigate another pattern.
|
e695563
to
8c67606
Compare
Also just pushed updates to the following packages to remove usage of the global DOM shim in its code/tests/READMEs:
There is now no usage of the global DOM shim in any of our packages. |
See also lit/lit.dev#1026 which updates the lit.dev docs to account for this new approach of automatic shimming. |
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.
awesome!
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 is fantastic! Super excited to see this land.
Minor suggestions for importing render
from @lit-labs/ssr
in other packages.
.changeset/empty-cooks-clap.md
Outdated
@@ -0,0 +1,5 @@ | |||
--- | |||
'@lit-labs/eleventy-plugin-lit': minor |
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.
Wonder if this change should be major since it's potentially removing previously shimmed globals?
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.
Yeah it should be, but since we're still on 0.x.x
we have to call it minor
or else changesets will release 1.0.0
.
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.
Although now that I think of it, let's just release 1.0.0
Co-authored-by: Augustine Kim <[email protected]>
Co-authored-by: Augustine Kim <[email protected]>
Co-authored-by: Augustine Kim <[email protected]>
Co-authored-by: Augustine Kim <[email protected]>
50182cf
to
14b0d94
Compare
This updates the lit.dev SSR documentation to account for the changes in lit/lit#3522, namely the removal of the global DOM shim.
Adds a new
@lit-labs/ssr-dom-shim
package which exportsElement
,HTMLElement
,CustomElementRegistry
, and a default globalcustomElements
(but does not register any of them as globals).Updates
@lit/reactive-element/reactive-element.js
to import from this package in its node build, instead of providing inline no-op versions. This means the parts of the DOM shim required for most Lit components will always be loaded in Node, so that users don't need to think about loading the DOM shim at all anymore.When using this new automatic shimming by importing
reactive-element
from Node, only a single global will now be defined:customElements
. So in particular,window
will not be defined, solving many issues we encountered with libraries sniffing forwindow
to switch between node vs browser modes.ModuleLoader
now provides a default VM global context object which provides basic globals that are available in both Node and browsers. A context object can also be directly created with a newmakeDefaultContextObject
function.Updates
lit-html/experimental-hydrate.js
to not depend onbtoa
when running in Node, instead using Node's built-inBuffer
.Updates the existing
@lit-labs/ssr/lib/dom-shim.js
module to importHTMLElement
andcustomElements
from the new package, so that the same base class and registry are used when the full DOM shim is loaded.Makes registering a duplicate element in the DOM shim throw an exception.
Misc minor improvements to the DOM shim code, including moving APIs from
HTMLElement
toElement
, which is the correct interface for them.Updates to the following packages to remove usage of the global DOM shim in code/tests/READMEs:
@lit-labs/testing
@lit-labs/eleventy-plugin-lit
@lit-labs/ssr
@lit/localize-tools
See also lit/lit.dev#1026 which updates the lit.dev docs for these changes.
Fixes #3523