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

document.documentElement could be null actually #50078

Closed
JounQin opened this issue Jul 28, 2022 · 5 comments
Closed

document.documentElement could be null actually #50078

JounQin opened this issue Jul 28, 2022 · 5 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@JounQin
Copy link

JounQin commented Jul 28, 2022

Bug Report

🔎 Search Terms

document.documentElement

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

💻 Code

document.documentElement // `HTMLElement | null` expected

document.documentElement.remove() // `document.documentElement` is `null` now

🙁 Actual behavior

image

🙂 Expected behavior

readonly documentElement: HTMLElement | null
@MartinJohns
Copy link
Contributor

Related: #29052 (comment)

I'd say over 99 % of the cases it's never null, so changing this would be a real nuisance for close to no benefit.

@JounQin
Copy link
Author

JounQin commented Jul 28, 2022

I don't think they are same, document.documentElement! is very easy to handle the impossible null value.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 28, 2022
@RyanCavanaugh
Copy link
Member

I don't think this is a condition we need to make all programs concern themselves with. If you remove the element, please put it back before someone else notices it's gone 😅

@JounQin
Copy link
Author

JounQin commented Jul 28, 2022

If you remove the element, please put it back before someone else notices it's gone 😅

I'm working on a DOM sanitizer at https://github.com/un-ts/domiso/blob/main/src/index.ts#L68, and it could be a parsererror on parsing svg, so the incorrect element is removed as intended, I don't think I should add document.documentElement back?

@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants