Skip to content

Conversation

@jitrodriguez
Copy link
Contributor

@jitrodriguez jitrodriguez commented Aug 24, 2025

Fixes #4855

Update the document selection logic in lit-html.ts to also check whether
document.createTreeWalker is a function:

const d =
  NODE_MODE && typeof global.document?.createTreeWalker !== 'function'
    ? ({ createTreeWalker() { return {}; } } as unknown as Document)
    : document;

If the function is missing, lit-html falls back to its internal mock.


Did not add a unit test here, since the fallback path is decided at module evaluation time (const d = ...), and in the existing test files lit-html is already imported at the top.
This makes it impossible to toggle document.createTreeWalker before the module loads without introducing brittle dynamic-import tricks or extracting a new helper function, which I wanted to avoid to keep this fix minimal.

@changeset-bot
Copy link

changeset-bot bot commented Aug 24, 2025

🦋 Changeset detected

Latest commit: bc74509

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
lit-html Patch
lit Patch
lit-element Patch
@lit/reactive-element Patch

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

Copy link
Collaborator

@justinfagnani justinfagnani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jitrodriguez!

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.

[lit-html] document mock check is too loose

2 participants