WebReflection / WebReflection/linkedom

[bug] document shortcut element properties lose their children

Open
#283 0 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

What happened

@WebReflection the following test case in Jest:

it('should be the same <body /> element', () => {
  const { document } = parseHTML(`<body><div class="whatever"></div></body>`);
  const body = document.querySelector('body'),

  expect(body).toBe(document.body);
});

outputs this kind of result:

- Expected  - 0
+ Received  + 6

+ <body>
+   <head />
    <body />
+   <div
+     class="whatever"
+   />
+ </body>

Real world

https://github.com/freeCodeCamp-China/article-webpage-to-markdown-action/pull/32/files#diff-5cdb43bc3113537f238168168c0a52ab488039b63c51cbfc7938b22a2b589c53

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

Reproduce the reported Jest case using parseHTML with a body containing a div, then inspect how document.body and the body shortcut element are constructed. Trace the shortcut element's child handling and verify that document.querySelector('body') is identical to document.body while preserving the head and div children.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.