Improve unfinished-comments detection logic - #3707
Conversation
|
The feature should now work correctly in both of these cases:
|
| documentTitle = undefined; | ||
| } else if (document.visibilityState === 'hidden' && hasDraftComments()) { | ||
| function updateDocumentTitle(): void { | ||
| if (document.visibilityState === 'hidden' && hasDraftComments() && !documentTitle) { |
There was a problem hiding this comment.
I know it's ugly, but the nested if was here to account for the case where a comment is sent from a hidden tab but there are still drafts somewhere on the page (and thus the title shouldn't be reset).
But maybe this possibility doesn't exist in the first place?
There was a problem hiding this comment.
You're right, the 2 conditions aren't equivalent when "is hidden, has draft and has a documentTitle". I don't know if it matters at the moment because the change doesn't fix the issue, as mentioned in the other comment.
|
I tested both your last commit and my commit, and neither one actually catch the situation described by #3694 (comment)
If possible, perhaps, the easier way is to exclude "sending" textareas in return select.all('textarea').some(textarea => textarea.value.length > 0 && textarea.offsetWidth > 0 && !textarea.closest('.is-sending')); // made-up class |
So the solution would be to mark the submitted forms with a class/attribute in the |
|
I expect GitHub to already be doing that, so look for such a class in the dom first. |
Maybe I didn't look in the right place, but I found no such class. EDIT: I went ahead and implemented a proper fix using a custom class to tag the sending forms. Tested in both Firefox and Chromium and it works as expected. |
The fields and forms don't appear to have the class, but what do you think about looking for non-disabled Comment buttons instead? This slightly complicates the selector to cover the various types of comments and merge commits descriptions, but we wouldn't have to check the content nor the visibility. Example: |
After a few quick tests, I see two problems with this approach:
|
fregante
left a comment
There was a problem hiding this comment.
Ok I found a solution for the class removal.
| return select.all<HTMLTextAreaElement>('textarea:not([disabled])').some(textarea => | ||
| textarea.value !== textarea.textContent && // Exclude comments being edited but not yet changed (and empty comment fields) | ||
| textarea.offsetWidth > 0 && // Exclude invisible fields | ||
| !textarea.closest('.rgh-is-sending-comment') // Exclude forms being submitted |
There was a problem hiding this comment.
I think this would cover:
- regular comments
- review comments
- PR merges
| !textarea.closest('.rgh-is-sending-comment') // Exclude forms being submitted | |
| select.exists('.btn-primary[disabled]', textarea.form!); |
This reads as: if the form of the current textarea (which is filled, changed, and visible) contains a disabled "submit" button, then the textarea is being sent.
I'm not sure if the selector needs to be tweaked.
There was a problem hiding this comment.
Tested all three cases and they work great! Although the feature doesn't work when creating a new issue/PR — but I don't think it was the goal in the first place?
There was a problem hiding this comment.
I think that's just due to pageDetect.hasComments. Perhaps the correct one is hasRichTextEditor
unfinished-comments detection logic
|
Thanks @cheap-glitch! |

Thanks for contributing! 🍄
LINKED ISSUES: Add
unfinished-commentsfeature #3694 (cf. this comment)TEST URLS: Improve
unfinished-commentsdetection logic #3707SCREENSHOT: n/a