Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Meta: Correctly deinit all features - #5422

Merged
cheap-glitch merged 27 commits into
mainfrom
deinit-everything
Mar 18, 2022
Merged

cheap-glitch merged 27 commits into
mainfrom
deinit-everything

Conversation

@cheap-glitch

@cheap-glitch cheap-glitch commented Feb 17, 2022

Copy link
Copy Markdown
Contributor

#5222 (comment)

This PR:

  • adds the global Deinit type and use it in every relevant init return type
  • makes sure that every feature is correctly "deinitified"
  • deinitifies the additionalListeners too
  • passes an AbortSignal to init functions and uses it in as many addEventListener as possible
  • drops every onetime(init) where it makes sense

@cheap-glitch cheap-glitch added the meta Related to Refined GitHub itself label Feb 17, 2022
@fregante

Copy link
Copy Markdown
Member

responsibility12(alternate)

@fregante

Copy link
Copy Markdown
Member

😱
3332f6ef40a0ae9dd34d6d5eaa7e7524656a1f77

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread source/features/conversation-activity-filter.tsx
Comment thread source/features/fit-textareas.tsx Outdated
Comment thread source/features/fit-textareas.tsx Outdated
Comment thread source/features/index.tsx Outdated
Comment thread source/features/index.tsx
Comment thread source/features/selection-in-new-tab.tsx Outdated
Comment thread source/features/sticky-sidebar.tsx
Comment thread source/features/sync-pr-commit-title.tsx Outdated
Comment thread source/github-events/on-new-comments.ts Outdated
Comment thread source/github-events/on-new-comments.ts
Comment thread source/features/batch-mark-files-as-viewed.tsx
Comment thread source/features/copy-on-y.tsx Outdated
Comment thread source/features/esc-to-deselect-line.tsx Outdated
@yakov116

This comment was marked as outdated.

@cheap-glitch cheap-glitch left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current state of this PR:

Comment thread source/features/improve-shortcut-help.tsx Outdated
Comment thread source/features/reactions-avatars.tsx
@cheap-glitch
cheap-glitch marked this pull request as ready for review February 21, 2022 19:43
@fregante

fregante commented Mar 5, 2022

Copy link
Copy Markdown
Member

@refined-github/maintainers
We're going to need help reviewing and merging this soon

Comment thread source/features/fit-textareas.tsx Outdated
Comment thread source/features/improve-shortcut-help.tsx Outdated
Comment thread source/github-events/on-pr-merge-panel-open.ts
Comment thread source/features/wait-for-attachments.tsx
document.removeEventListener('upload:setup', toggleSubmitButtons, {capture: true});
document.removeEventListener('upload:complete', toggleSubmitButtons);
document.removeEventListener('upload:error', toggleSubmitButtons);
document.removeEventListener('upload:invalid', toggleSubmitButtons);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}}) => {

@fregante fregante Mar 5, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread source/features/pr-branch-auto-delete.tsx Outdated
pageDetect.isDiscussion,
],
init: onetime(discussionInit),
init: discussionInit,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need some extra eyes on this file. helpppp review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fregante Should I move those changes to a separate PR?

Comment thread source/features/sync-pr-commit-title.tsx
@yakov116

This comment was marked as outdated.

@fregante

Copy link
Copy Markdown
Member

Let's merge this after the next release, so we have time to review

@fregante
fregante marked this pull request as draft March 15, 2022 07:57
@fregante
fregante marked this pull request as ready for review March 17, 2022 05:35
@fregante

fregante commented Mar 17, 2022

Copy link
Copy Markdown
Member

v22.3.17 is out, plz merge

edit: we need to release a hotfix for #5520

@fregante
fregante marked this pull request as draft March 17, 2022 09:43
@fregante
fregante marked this pull request as ready for review March 18, 2022 05:23
@cheap-glitch
cheap-glitch merged commit afb434c into main Mar 18, 2022
@cheap-glitch
cheap-glitch deleted the deinit-everything branch March 18, 2022 10:36
@cheap-glitch

Copy link
Copy Markdown
Contributor Author

(╯°□°)╯︵ O˥O⅄

@fregante

Copy link
Copy Markdown
Member

Hey, by the way, I got good news: signal is now supported in Safari 15.4, soooooo, no more () => el.removeEventListener() needed 🎉

@fregante

fregante commented Mar 18, 2022

Copy link
Copy Markdown
Member

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

@cheap-glitch

Copy link
Copy Markdown
Contributor Author

Hey, by the way, I got good news: signal is now supported in Safari 15.4, soooooo, no more () => el.removeEventListener() needed

Welp, now MDN says it's been supported since v15 🥲 should have tested it myself.

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 🤷‍♂️

@fregante

Copy link
Copy Markdown
Member

Yeah same, they must have updated it now, we were looking at an incorrect table

@fregante

fregante commented Apr 4, 2022

Copy link
Copy Markdown
Member

I think this broke a few things, I get this error consistently now:

Screen Shot 6

and since 22.4.1 I'm now seeing this:

Screen Shot 4

@cheap-glitch

Copy link
Copy Markdown
Contributor Author

I think this broke a few things, I get this error consistently now

Weird, I never get these on Firefox

and since 22.4.1 I'm now seeing this

+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;

@fregante fregante Apr 4, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I never get these on Firefox

The methods are probably not bound on Safari. The changes required look like:

Suggested change
return deinit.disconnect;
return () => deinit.disconnect();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I had this bug in Firefox too but only with controller.abort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Related to Refined GitHub itself

Development

Successfully merging this pull request may close these issues.

4 participants