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

Fix crash when using instanceof HTMLElement in some environments #3494

Merged
merged 3 commits into from
Sep 27, 2024

Conversation

RobinMalfait
Copy link
Member

This PR fixes an issue where in some environments where HTMLElement is not
available (on the server) and AG Grid is used, we crashed.

This happens because the HTMLElement is polyfilled to an empty object. This means that the typeof HTMLElement !== 'undefined' check passed, but the v instanceof HTMLElement translated to v instanceof {} which is invalid and resulted in a crash...

This PR solves it by checking for exactly what we need, in this case whether the outerHTML property is available.

Alternatively, we could use return v?.outerHTML ?? v, but not sure if that's always safe to do.

Fixes: #3471

Copy link

vercel bot commented Sep 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2024 9:35am
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2024 9:35am

@RobinMalfait
Copy link
Member Author

@thecrypticace thoughts on this solution compared to v?.outerHTML ?? v?

@thecrypticace
Copy link
Contributor

Honestly I think I'd use v?.outerHTML ?? v — just throw in a comment as to why because I know we'll forget.

Aside: If AG Grid is polyfilling HTMLElement to {} and not at least function HTMLElement() {} that is absolutely a bug in AG Grid.

@thecrypticace
Copy link
Contributor

I guess the only reason it wouldn't be safe is if String.prototype.outerHTML was defined right? But that would be really bizarre. So I guess we could check for an object. I'm fine with either honestly.

Some tools, like AG Grid, polyfill `HTMLElement` to an empty object.
This means that the `typeof HTMLElement !== 'undefined'` check passed,
but the `v instanceof HTMLElement` translated to `v instanceof {}` which
is invalid...

This hopefully solves it.

Alternatively, we could use `return v?.outerHTML ?? v`, but not sure if
that's always safe to do.
@RobinMalfait
Copy link
Member Author

Aside: If AG Grid is polyfilling HTMLElement to {} and not at least function HTMLElement() {} that is absolutely a bug in AG Grid.

100% agree, if they do that for test code in their own tests that's one thing. But this is in production, so definitely not ideal.

Either way, with this PR the code is a bit cleaner as well so why not..

@RobinMalfait RobinMalfait merged commit 63daa86 into main Sep 27, 2024
8 checks passed
@RobinMalfait RobinMalfait deleted the fix/issue-3471 branch September 27, 2024 09:39
@NPJigaK
Copy link

NPJigaK commented Oct 2, 2024

When will it be released?

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.

[Listbox] Right-hand side of 'instanceof' is not callable (SSR)
3 participants