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

[reactive-element] Fix Node build auto-shimming of HTMLElement to respect existing global shim #3561

Merged
merged 4 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/thick-wasps-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@lit/lit-starter-js': patch
'@lit/lit-starter-ts': patch
---

Update dependency `@rollup/plugin-replace`
6 changes: 6 additions & 0 deletions .changeset/tidy-lamps-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'lit': patch
'@lit/reactive-element': patch
---

Fix built-in shimming of `HTMLElement` for Node build of `reactive-element` to respect existing `HTMLElement` in global
108 changes: 92 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-inject": "^5.0.2",
"@rollup/plugin-node-resolve": "^13.2.1",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-virtual": "^2.1.0",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/lit-starter-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@custom-elements-manifest/analyzer": "^0.6.3",
"@open-wc/testing": "^3.1.5",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-replace": "^5.0.2",
"@web/dev-server": "^0.1.31",
"@web/dev-server-legacy": "^1.0.0",
"@web/test-runner": "^0.13.27",
Expand Down
2 changes: 1 addition & 1 deletion packages/lit-starter-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@custom-elements-manifest/analyzer": "^0.6.3",
"@open-wc/testing": "^3.1.5",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-replace": "^5.0.2",
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"@web/dev-server": "^0.1.31",
Expand Down
24 changes: 23 additions & 1 deletion packages/reactive-element/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@
"test:dev": "wireit",
"test:prod": "wireit",
"test:node": "wireit",
"test:node-dev": "wireit"
"test:node-dev": "wireit",
"test:node-dom-shim": "wireit",
"test:node-dom-shim-dev": "wireit"
},
"wireit": {
"build": {
Expand Down Expand Up @@ -268,6 +270,8 @@
"test:prod",
"test:node",
"test:node-dev",
"test:node-dom-shim",
"test:node-dom-shim-dev",
"check-version"
]
},
Expand Down Expand Up @@ -319,6 +323,24 @@
],
"files": [],
"output": []
},
"test:node-dom-shim": {
"command": "node development/test/node-dom-shim.js",
"dependencies": [
"build:ts",
"build:rollup"
],
"files": [],
"output": []
},
"test:node-dom-shim-dev": {
"command": "node --conditions=development development/test/node-dom-shim.js",
"dependencies": [
"build:ts",
"build:rollup"
],
"files": [],
"output": []
}
},
"files": [
Expand Down
25 changes: 25 additions & 0 deletions packages/reactive-element/src/test/node-dom-shim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/

// This file will be loaded by Node from the node:test-dom-shim script to verify
// `ReactiveElement` will prefer extending existing `HTMLElement` from the
// global rather than the built-in shim

import './node-shim-html-element.js';
import {ReactiveElement} from '@lit/reactive-element';
import {HTMLElement} from '@lit-labs/ssr-dom-shim';

import assert from 'node:assert/strict';
assert.strictEqual(
Object.getPrototypeOf(ReactiveElement),
globalThis.HTMLElement,
'Expected ReactiveElement to extend existing globalThis.HTMLElement'
);
assert.notStrictEqual(
Object.getPrototypeOf(ReactiveElement),
HTMLElement,
'Expected ReactiveElement to not extend HTMLElement from ssr-dom-shim'
);
8 changes: 8 additions & 0 deletions packages/reactive-element/src/test/node-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ export class MyElement extends ReactiveElement {

export class MyOtherElement extends ReactiveElement {}
customElements.define('my-other-element', MyOtherElement);

import assert from 'node:assert/strict';
import {HTMLElement} from '@lit-labs/ssr-dom-shim';
assert.strictEqual(
Object.getPrototypeOf(ReactiveElement),
HTMLElement,
'Expected ReactiveElement to extend HTMLElement from ssr-dom-shim'
);
11 changes: 11 additions & 0 deletions packages/reactive-element/src/test/node-shim-html-element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/

// This file is used as a side-effectful import in `node-dom-shim.js` to
// simulate loading a separate DOM shim that adds `HTMLElement` to the global

class FakeHTMLElement {}
globalThis.HTMLElement = FakeHTMLElement as typeof HTMLElement;
1 change: 1 addition & 0 deletions rollup-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ const injectNodeDomShimIntoReactiveElement = [
include: ['**/packages/lit-html/development/experimental-hydrate.js'],
}),
replace({
preventAssignment: true,
values: {
'extends HTMLElement': 'extends (globalThis.HTMLElement ?? HTMLElement)',
},
Expand Down