Skip to content

Fix console error in quick-label-removal #4939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions source/features/quick-label-removal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ async function removeLabelButtonClickHandler(event: delegate.Event<MouseEvent, H
});

removeLabelButton.closest('a')!.remove();

// Force update of label selector if necessary
if (!select.exists('.sidebar-labels include-fragment')) {
const deferredContentWrapper = select('.sidebar-labels .hx_rsm-content')!;
const menu = deferredContentWrapper.closest('[src]')!;
deferredContentWrapper.textContent = '';
deferredContentWrapper.append(<include-fragment src={menu.getAttribute('src')!}/>);
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this is still beneficial.

In #4953 I removed a label and then opened the menu to add one. The label was still selected in there and it added the label again.

Maybe a "simpler" or safer alternative would be to look for the specific label in the dropdown and disable it there as well, to avoid this specific issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that bug too.

The fix is tricky, because immediately replacing the dropdown content with an include fragment doesn't always work, especially when removing several labels in quick succession and then opening the dropdown right away.

Maybe we should add a listener on the dropdown button? The logic would be:

  1. When a label is removed, mark the dropdown as "outdated" but don't actually force it to update
  2. Listen to the opening of the dropdown. If it's outdated and GitHub hasn't already updated its contents (i.e. no include fragments is already there), replace them with an <include-fragment>.

Maybe a "simpler" or safer alternative would be to look for the specific label in the dropdown and disable it there as well, to avoid this specific issue

Changing the aria-selected attribute of a label in the dropdown has zero effect, it's purely cosmetic.

Copy link
Member

Choose a reason for hiding this comment

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

I don't remember how it works, but doesn't GitHub already use a "data-url" attribute that is then loaded as a fragment when the user clicks it? If it is, then we just need to set it again and empty the dropdown. GitHub will then take care of loading it as usual.

I don't want something super complicated though 😬 I think this would be good if it works

}

async function init(): Promise<void> {
Expand Down