Repository navigation
Fix console errors in PR merging box features - #5549
Conversation
cheap-glitch
left a comment
There was a problem hiding this comment.
This PR drops the session:resume listener used in onPrMergePanelOpen because of its unreliability (see linked issue for details), and adds two extra listeners to allow for more granularity in each feature:
onPrMergePanelOpennow reacts only to the opening of the merge panel (i.e. when clicking on one of the green Merge buttons).onPrMergePanelLoadreacts to the initial loading of the merge panel, but in a more reliable way. This is a feature of GitHub that directly show the merge field on page load iff any of their content have been modified from the defaults.onPrCommitMessageRestoreis built on the previous listener and is triggered when GitHub restores the modified contents of the merge fields.
| // Triggering input event for these fields immediately validates the form | ||
| onPrMergePanelOpen, | ||
| // For PR merges, GitHub restores any modified commit messages on page load | ||
| onPrCommitMessageRestore, |
There was a problem hiding this comment.
suggest-commit-title-limit.mp4
| // Only if the user hasn't already interacted with it in this session | ||
| if (field && event.type !== 'session:resume') { |
There was a problem hiding this comment.
The listener explicitly excluded the case of the panel content being restored, so we can just use the more restrictive onPrMergePanelToggle instead.
| listeners.push( | ||
| ...onPrMergePanelOpen(updateCommitTitle), | ||
| onPrCommitMessageRestore(updateUI), | ||
| onPrMergePanelOpen(updateCommitTitle), |
There was a problem hiding this comment.
Though we still want to show the UI if the commit message has been modified:
sync-pr-commit-title.mp4
| } | ||
|
|
||
| function watchForNewCommits(): MutationObserver { | ||
| let commitObserver: undefined | MutationObserver; |
There was a problem hiding this comment.
I used a global listener because it's the simplest way to ensure it's not created twice, since the callback could be called twice in a session: the first time when the merge panel is loaded, and the second if it's closed (with "Cancel") and then reopened (which would trigger the toggle listener).
| async function init(signal: AbortSignal): Promise<Deinit[]> { | ||
| // Warn user if it's not yet submitted | ||
| window.addEventListener('beforeunload', onBeforeunload); | ||
| window.addEventListener('beforeunload', onBeforeunload, {signal}); |
There was a problem hiding this comment.
This anticipates #5523 a bit to make things easier.
| onPrMergePanelLoad(onPrMergePanelHandler), | ||
|
|
||
| onPrMergePanelOpen(() => { | ||
| const {signal} = deinitController; | ||
| if (signal.aborted) { | ||
| return; | ||
| } | ||
|
|
||
| showCheckboxIfNecessary(); | ||
| const observer = watchForNewCommits(); | ||
| signal.addEventListener('abort', observer.disconnect, {once: true}); | ||
| }), | ||
| onPrMergePanelOpen(onPrMergePanelHandler), |
There was a problem hiding this comment.
wait-for-checks.mp4
Video taken with the checkbox always enabled for obvious demonstration purposes.
| const getDeduplicatedHandler = mem((callback: EventListener): EventListener => () => { | ||
| // Wait for GitHub to update the contents of the merge commit summary field | ||
| select('input#merge_title_field')!.addEventListener('change', callback, {once: true}); | ||
| }); | ||
|
|
||
| export default function onPrCommitMessageRestore(callback: EventListener): delegate.Subscription { | ||
| return onPrMergePanelLoad(getDeduplicatedHandler(callback)); | ||
| } |
There was a problem hiding this comment.
The contents of the PR merge fields are not immediately restored upon load, so we wait for the panel to load and then attach a listener to the <input> element that will be triggered by GitHub's code.
|
Two related comments that can't be reviews because the files haven't been touched 👇 In Then on subsequent reloads, any changes the feature made to the commit description will automatically be restored by GitHub. The But it's somewhat unreliable, so it will have to be revised too. |
|
The demo videos look good. It would be good to outline the specific situations that our listeners cover, including past fixes we applied, so that we can use it as a test checklist. For example:
Or simply list all the "events" that affect the box, like:
|
|
This PR can be merged after 22.4.1 as is, though |
+1 Actually, I've been thinking that we could really use a permanent list of testing URLs for often-modified features or features that have a lot of edge cases (e.g. Just a Markdown file somewhere in the repo would be good enough. |
|
We can include these details in the feature itself. Adding large comments isn't an issue, we can append them to the file, so they follow the init |
Fixes #5547
Test URLs
Screenshots
See the review comments below.