WebReflection / WebReflection/linkedom

Event `target` not reflected correctly for `defaultView`

Open
#298 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
2.1k
Forks
104
PR merge metrics
No merged PRs in 30d

Description

Running this (in nodejs v20.18.1):

import { parseHTML } from "linkedom";
const { document, window } = parseHTML();

for (let name of ["document", "window"]) {
  window[name].addEventListener("test", (e) =>
    console.assert(e.target === window[name], `${name} preserves target`)
  );
  window[name].dispatchEvent(new window.Event("test"));
}

logs this:

Assertion failed: window preserves target

It seems that the target set for events dispatched from defaultView ends up being globalThis, not defaultView.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the provided parseHTML reproduction as the first test case; trace how window/defaultView dispatches Event and assigns target. Done when the window listener observes e.target === window while the document behavior remains correct, with a regression test covering both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.