Skip to content
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

Updates for removed global DOM shim #1026

Merged
merged 2 commits into from
Jan 9, 2023
Merged

Updates for removed global DOM shim #1026

merged 2 commits into from
Jan 9, 2023

Conversation

aomarks
Copy link
Member

@aomarks aomarks commented Jan 6, 2023

This updates the lit.dev SSR documentation to account for the changes in lit/lit#3522, namely the removal of the global DOM shim.

@github-actions
Copy link

github-actions bot commented Jan 6, 2023

A live preview of this PR will be available at the URL(s) below.
The latest URL will be appended to this comment on each push.
Each build takes ~5-10 minutes, and will 404 until finished.

https://pr1026-c1bc2ed---lit-dev-5ftespv5na-uc.a.run.app/
https://pr1026-8fdd8fc---lit-dev-5ftespv5na-uc.a.run.app/

aomarks added a commit to lit/lit that referenced this pull request Jan 6, 2023
- Adds a new `@lit-labs/ssr-dom-shim` package which exports `Element`, `HTMLElement`, `CustomElementRegistry`, and a default global `customElements` (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 for `window` 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 new `makeDefaultContextObject` function.

- Updates `lit-html/experimental-hydrate.js` to not depend on `btoa` when running in Node, instead using Node's built-in `Buffer`.

- Updates the existing `@lit-labs/ssr/lib/dom-shim.js` module to import `HTMLElement` and `customElements` 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` to `Element`, 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
@aomarks aomarks merged commit 65b214f into main Jan 9, 2023
@aomarks aomarks deleted the remove-global-dom-shim branch January 9, 2023 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants