Repository navigation
Deinit native event listeners in features using AbortSignal - #5523
Conversation
| ...onPrMergePanelOpen(updateCommitTitle), | ||
| function init(signal: AbortSignal): Deinit { | ||
| subscriptions.push( | ||
| onPrMergePanelOpen(updateCommitTitle, signal), |
There was a problem hiding this comment.
This can't work because the signal is managed by the global manager but this array is local and we must be able to deinit it here.
There was a problem hiding this comment.
We have 2 quick solutions here:
- drop the changes made to
onPrMergePanelOpenand to this file - create a local abortcontroller so that
onPrMergePanelOpencan keep its improvement
For the latter, probably:
function init() {
// Local controller needed because the feature can be deinited locally
const controller = new AbortControler()
subscriptions.push(
onPrMergePanelOpen(updateCommitTitle, signal),
() => controller.abort(),
etcOther, more involved solutions, that should be done separately:
- (in this feature) only use a local controller and have
deinitcall that.initwould returncontroller.abort - add an API that allows a feature to deinit itself on demand, like:
This would free us from having to deal with the local
function deinit() { features.deinit(import.meta.url) }
listeners/subscriptionsarrays
There was a problem hiding this comment.
This can't work because the signal is managed by the global manager but this array is local and we must be able to deinit it here.
This was actually rendered moot by #5549 😅
The native listener was dropped, so now it just returns a delegate subscription.
add an API that allows a feature to deinit itself on demand
I like that idea, as long as we reserve it for special or tricky cases.
AbortSignalAbortSignal
|
Let's merge this when it passes review, we can include fregante/delegate-it#26 later when it's done. |
| } | ||
|
|
||
| function setupDeinit(deinit: Deinit): void { | ||
| document.addEventListener('pjax:start', getDeinitHandler(deinit), {once: true}); |
There was a problem hiding this comment.
setupPageLoad already attaches an ajaxed event listener, so we should change this function to something like:
function onPageUnload(signal, deinit: Deinit): void {
signal.addEventListener('abort', getDeinitHandler(deinit));
Follow-up of #5422
Let's do fregante/delegate-it#26 while we're at it 🔥