Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork43
Added host to hooks for instanceof check#100
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ZeeCoder commentedDec 16, 2022
Hi@nerocui 👋 First of all: thank you, I really appreciate the effort here! Can you provide a reproduction of your issue in codesandbox, so that I better understand your use-case please? 🙏 |
nerocui commentedJan 3, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@ZeeCoder Happy new year. Hope you had a good holiday break. Please let me know if this helps. |
ZeeCoder commentedFeb 18, 2023
Sorry I didn't come back to you yet, I'm extremely busy with personal stuff right now but I just wanted you to know I appreciate the time you've invested here. use-resize-observer/src/utils/useResolvedElement.ts Lines 30 to 37 in490429f
I think one solution would be to change this: constelement:T|null=cbElement ?cbElement :refOrElement ?refOrElementinstanceofElement ?refOrElement :refOrElement.current :null; To this: constelement:T|null=cbElement ?cbElement :refOrElement ?"current"inrefOrElement ?refOrElement.current :refOrElement :null; ☝️ Basically by not using instanceof at all, we circumvent the issue altogether. Could be a minor release. 🤔 |
ZeeCoder commentedFeb 18, 2023
Would need an additional test case ofc to ensure there'd be no regressions. |
nerocui commentedFeb 18, 2023
@ZeeCoder Thank you so much for looking into it! Yes getting rid of interaction with global objects would solve this issue. |
nerocui commentedFeb 18, 2023
I'll update the PR with the recommendation and test cases. |
bpinto commentedFeb 22, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Alternatively, using constelement=cbElement||(refOrElement ?Object.prototype.hasOwnProperty.call(refOrElement,'current') ?refOrElement.current :refOrElement :null) |
ZeeCoder commentedFeb 24, 2023
@bpinto looks about right, it's a shame that TS doesn't handle it properly though: |
bpinto commentedFeb 26, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Sorry@ZeeCoder, I have 0 experience with TS but a google search showed me the following solution: Type assertion since we know it's a ref and not an element/state: I tested ithere |

Hi@ZeeCoder , thanks for creating this library. We are using this package, and we'd like to help make it better. Our use case includes passing in child window's window object.
instanceofchecks the prototype, and that's unique on each window. So to make sureinstanceofworks reliably, we need to pass in the host object and compare to the correctElement. Default case is the globalwindowobject.Hope you could give this PR a look when you are free. Thank you!