Skip to content

Fix show-whitespace on newly sent suggestions - #5106

Merged
cheap-glitch merged 4 commits into
mainfrom
show-whitespace-on-suggestions
Dec 11, 2021
Merged

cheap-glitch merged 4 commits into
mainfrom
show-whitespace-on-suggestions

Conversation

@cheap-glitch

Copy link
Copy Markdown
Contributor

@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.

Attempt at implementing a listener for new review comments.

Comment thread source/github-events/on-new-review.ts Outdated
}

export default function onNewReviewComment(callback: VoidFunction): void {
delegate(document, '.js-pull-refresh-on-pjax', 'socket:message', callbackWrapper(callback), {capture: true});

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.

This triggers on other events besides new reviews, e.g. when editing or deleting reviews.

In the first case it's actually a good thing I guess, because the contents of the embedded snippets might have been changed and/or added.

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.

socket:message can't be used I think. The message doesn't always equal DOM change, which sometimes happens later. We had this issue a few years ago when implementing onNewComments, not sure if it applies here.

If it works… it's fine for now.

Comment thread source/github-events/on-new-review.ts Outdated

function callbackWrapper(callback: VoidFunction): (event: CustomEvent) => void {
return function (event) {
if (/^pull request #\d+ updated$/.test(event.detail.data.reason)) {

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.

Not sure if the test is really needed, it seems all the messages are the same (with just the id changing).

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.

The issue is that this event might also be dispatched when a regular comment comes in, so it would effectively duplicate onNewComment as well.

@cheap-glitch cheap-glitch Nov 23, 2021 •

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.

The issue is that this event might also be dispatched when a regular comment comes in

It is, but not from the same source, so the delegation ignores it.

The issue is that it is dispatched three times when sending a quick review (with "Add single review comment" button), and afaict the three events are virtually indistinguishable

Edit: seems like debouncing does the trick 🤔

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.

That doesn't sound right. What's happening though is that we have a simple loop with deduplication in init. So even if it's called twice, no duplication happens.

It may be ok, but I'm still wary of this event and I'd probably merge it back into this file so we know it's not safe for general use. A comment like this should also be inlined.

@cheap-glitch
cheap-glitch marked this pull request as ready for review November 22, 2021 18:32
Comment thread source/github-events/on-new-review.ts Resolved
@yakov116 yakov116 changed the title Fix: show-whitespace doesn’t work on newly sent suggestions Fix: show-whitespace on newly sent suggestions Nov 23, 2021
@cheap-glitch cheap-glitch changed the title Fix: show-whitespace on newly sent suggestions Fix show-whitespace on newly sent suggestions Nov 29, 2021
@fregante
fregante marked this pull request as draft December 3, 2021 16:16
@cheap-glitch
cheap-glitch marked this pull request as ready for review December 11, 2021 16:48
@cheap-glitch
cheap-glitch merged commit fc8428b into main Dec 11, 2021
@cheap-glitch
cheap-glitch deleted the show-whitespace-on-suggestions branch December 11, 2021 16:48
@kidonng

kidonng commented Dec 13, 2021

Copy link
Copy Markdown
Member

Thanks for solving an oldest bug 🔥

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

Labels

Development

Successfully merging this pull request may close these issues.

show-whitespace doesn’t work on newly sent suggestions

3 participants