-
Notifications
You must be signed in to change notification settings - Fork 60
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
Move hooks into Window instance #402
Conversation
a008cd2
to
6989327
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change a lot, thanks for putting it together. I left a few comments but I think this is quite close 👍
if (this[OWNER_DOCUMENT]) { | ||
this[OWNER_DOCUMENT].defaultView[HOOKS].setText?.(this as any, str); | ||
} else { | ||
setTimeout(() => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an issue because of us calling setData
in the constructor, right? Instead of doing this, could we just assign to this[DATA]
directly in the constructor (applying the same stringifying logic implemented above), which avoids this triggering a hook call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered that but that would skip the initial hook call and change the existing behaviour. I'm ok with that but it's a change in the existing behaviour. Alternatively, we can manually set the value via this[DATA]
and schedule the hook call within the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am OK to break this behavior. I think the library is actually broken in a different way here — we expose a createText
hook
createText(text: Text, data: string): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops haha Should I add setTimeout(() => this[HOOKS]?.createText ...)
here then?
df0c6de
to
1faebf7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks so much for this improvement Olavo!
Summary
The current implementation of the DOM polyfill uses an in memory singleton to manage internal hooks. This results in coupling of the polyfill with the global scope, preventing multiple instances of Window from being created without interfering with each other.
This PR refactors the management of these hooks by scoping them in the Window instance, decoupling the implementation from the global scope.