Meta: Correctly deinit all features - #5422
Conversation
fregante
left a comment
There was a problem hiding this comment.
oof, big PR.
Some changes are required for Safari compatibility. If you feel that they're too much, I think maybe those specific features can be excluded from this PR and maybe addressed separately
Co-authored-by: Federico Brigante <[email protected]>
Co-authored-by: Federico Brigante <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
cheap-glitch
left a comment
There was a problem hiding this comment.
Current state of this PR:
-
dropped the global signal in every
addEventListenercall, and instead made theinitreturn a wrapper(s) around theremoveEventListener(s). This concerns the following features:copy-on-yesc-to-deselect-linefile-finder-bufferhide-navigation-hover-highlightimprove-shortcut-helpkeyboard-navigationprevent-pr-merge-panel-openingselection-in-new-tabsticky-sidebarstop-pjax-loading-with-escunfinished-commentswait-for-attachmentswait-for-checks- plus
on-pr-merge-panel-open
-
kept the
AbortSignalin theinitof those three features, to use withonElementRemovalandonReplacedElement: -
used
setupDeinitdirectly in those two features, because I couldn't find a better way to deinit in nested callbacks:
|
@refined-github/maintainers |
| document.removeEventListener('upload:setup', toggleSubmitButtons, {capture: true}); | ||
| document.removeEventListener('upload:complete', toggleSubmitButtons); | ||
| document.removeEventListener('upload:error', toggleSubmitButtons); | ||
| document.removeEventListener('upload:invalid', toggleSubmitButtons); |
There was a problem hiding this comment.
In a later cleanup PR, I think we should just create the signal helper I mentioned before. This is so error-prone and I don't wanna see it.
The code would instead look like:
import on from '../heh'
function init(signal: AbortSignal): void {
on(document, 'upload:setup', toggleSubmitButtons, {signal, capture: true});
on(document, 'upload:complete', toggleSubmitButtons, {signal});
on(document, 'upload:error', toggleSubmitButtons, {signal});
on(document, 'upload:invalid', toggleSubmitButtons, {signal});
}and it would actually kinda mirror delegate (which would also benefit from fregante/delegate-it#26)
There was a problem hiding this comment.
Why not make that helper return a wrapper function containing a removeEventListener instead? It'd be more consistent with the way delegate works now imo.
| }); | ||
|
|
||
| // This will prevent submission when clicking "Comment" and "Request changes" without entering a comment and no other review comments are pending | ||
| return delegate(form, 'button', 'click', ({delegateTarget: {value}}) => { |
There was a problem hiding this comment.
oof, this function should probably be moved out (later PR). I think it's only jere because of form, which is actually accessible via delegateTarget.form
fregante
left a comment
There was a problem hiding this comment.
I reviewed everything with one exception, a couple of nits, a few things to fix later and just one thing that needs to be reverted.
Let's leave it open for a couple of days to allow some extra reviews (plz) then merge as you see fit
| pageDetect.isDiscussion, | ||
| ], | ||
| init: onetime(discussionInit), | ||
| init: discussionInit, |
There was a problem hiding this comment.
I need some extra eyes on this file. helpppp review
There was a problem hiding this comment.
@fregante Should I move those changes to a separate PR?
This comment was marked as outdated.
This comment was marked as outdated.
|
Let's merge this after the next release, so we have time to review |
|
v22.3.17 is out, plz merge edit: we need to release a hotfix for #5520 |
(╯°□°)╯︵ O˥O⅄ |
|
Hey, by the way, I got good news: |
|
Welp, now MDN says it's been supported since v15 🥲 should have tested it myself. https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#browser_compatibility |
Weird, I remember looking at the compat table and it was red. Maybe they only consider the major version because that's how the other browsers are doing it 🤷♂️ |
|
Yeah same, they must have updated it now, we were looking at an incorrect table |
Weird, I never get these on Firefox
+1 |
| @@ -0,0 +1,15 @@ | |||
| export default function getDeinitHandler(deinit: Deinit): VoidFunction { | |||
| if (deinit instanceof MutationObserver || deinit instanceof ResizeObserver || deinit instanceof IntersectionObserver) { | |||
| return deinit.disconnect; | |||
There was a problem hiding this comment.
Weird, I never get these on Firefox
The methods are probably not bound on Safari. The changes required look like:
| return deinit.disconnect; | |
| return () => deinit.disconnect(); |
There was a problem hiding this comment.
I see, I had this bug in Firefox too but only with controller.abort.





#5222 (comment)
This PR:
Deinittype and use it in every relevantinitreturn typeadditionalListenerstooAbortSignalto init functions and uses it in as manyaddEventListeneras possibleonetime(init)where it makes sense