-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Listbox] Right-hand side of 'instanceof' is not callable
(SSR)
#3471
Comments
I am facing the same issue |
Can we get your thoughts on this, @RobinMalfait? Happy to PR the try-catch if it helps, but not sure if that's the way you want to handle it. Thanks. 🙏 |
…3494) 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
Hey! This is 100% an AG Grid related bug and not an Headless UI bug. That said, we can simplify our code a bit to also get rid of the bug so we can do that in the meantime. This should be fixed by #3494, and will be available in the next release. You can already try it using:
|
Confirmed the refactored version no longer crashes. Thanks for doing that, even though it's definitely an AG Grid faux pas. 🙏 |
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v2.1.6 (but the problem can be reproduced beginning at v2.0.0)
What browser are you using?
N/A
Reproduction URL
Stackblitz: Vite SSR
Stackblitz: Remix
Stackblitz: Next.js
Describe your issue
When server rendering the Listbox component under certain circumstances, we get the following error:
As you can see by the provided reproduction URLs, we can reproduce this across various SSR implementations. If you SSR the Listbox in an isolated environment, everything seems to be fine. But there are certain circumstances that cause this error and one we've been able to nail down is when it's in a project that also uses AG Grid. This will cause Listbox to error consistently even if it's rendered on an unrelated route (that is, a separate route from where we render the grid).
Your distributed files are minified, which makes it harder to pin down the error, but after manually prettify-ing
@headlessui/react/dist/internal/floating.js
, it appears the error comes from this statement on line 140:In a project with just the Listbox,
typeof HTMLElement
isundefined
, so this line is not executed (due to the ternary condition not being met). However, in a project with AG Grid,typeof HTMLElement
is actuallyobject
and appears to be an empty object{}
which is not a valid right-hand operand forinstanceof
.This particular case is probably AG Grid doing something it shouldn't, but it wouldn't hurt to be more defensive here. Perhaps a try-catch and return
v
if it throws, or maybe there's some reliable way to ensureHTMLElement
will be a validinstanceof
operand, I'm not sure.Thoughts?
The text was updated successfully, but these errors were encountered: