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

[lit-html] Use existing document in Node build #3223

Merged
merged 2 commits into from Aug 18, 2022
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/selfish-lobsters-cheat.md
@@ -0,0 +1,6 @@
---
'lit-html': patch
'lit': patch
---

Use existing `document` in Node build
15 changes: 8 additions & 7 deletions packages/lit-html/src/lit-html.ts
Expand Up @@ -344,13 +344,14 @@ const markerMatch = '?' + marker;
// syntax because it's slightly smaller, but parses as a comment node.
const nodeMarker = `<${markerMatch}>`;

const d = NODE_MODE
? ({
createTreeWalker() {
return {};
},
} as unknown as Document)
: document;
const d =
NODE_MODE && global.document === undefined
? ({
createTreeWalker() {
return {};
},
} as unknown as Document)
: document;

// Creates a dynamic marker. We never have to search for these in the DOM.
const createMarker = (v = '') => d.createComment(v);
Expand Down