Skip to content

one-click-pr-or-gist - Disable draft button during upload - #10130

Merged
fregante merged 8 commits into
refined-github:mainfrom
erenbati:test/draft-upload-state-10118-current
Sep 30, 2026
Merged

fregante merged 8 commits into
refined-github:mainfrom
erenbati:test/draft-upload-state-10118-current

Conversation

@erenbati

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added the bug label Sep 26, 2026

@fregante fregante left a comment

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.

This is not what I meant, GitHub has a native behavior enabled via attributes (data-disabled-with?) so we should just use that

@erenbati

Copy link
Copy Markdown
Contributor Author

Updated this to use GitHub’s native data-disable-with="" behavior as suggested. The effective diff is now just that one attribute, and CI is green.

I couldn’t verify the Safari-specific runtime behavior from Windows/Chromium because GitHub’s native primary button stays enabled during upload there, so Chromium doesn’t reproduce the original issue.

@fregante fregante left a comment

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.

Two issues:

  • sadly this attribute does not fix the issue alone. I think fixing it might require reverse-engineering the way GitHub does this internally (which should be data-disable-with) and why it's not applied here
  • yes the issue appears in Chrome too, see gif:
Image

@fregante

Copy link
Copy Markdown
Member

I'd only consider a solution that is able to use GitHub's own handler for this without requiring explicit listeners or otherwise a bunch of code. It's "a small bug" and it deserves "a small fix" only

@fregante
fregante marked this pull request as draft September 29, 2026 11:07
@fregante

Copy link
Copy Markdown
Member

I found out why, GitHub's code targets .btn-primary specifically in the upload listeners:

function disableSubmit(event: CustomEvent & {currentTarget: Element}) {
  const closestForm = (event.target as HTMLElement).closest('form')

  if (closestForm) {
    const submitButton = closestForm.querySelector<HTMLButtonElement>('.btn-primary')
    if (submitButton) {
      submitButton.disabled = true
    }
  }
}

The only way to use this code would be to use .btn-primary on a fieldset parent, which natively disables all elements. This parent is found by GitHub and disabled, but unfortunately it comes with a lot of style:

Screenshot 5

However you can use display: contents to keep the logic but hide the element:

<fieldset class="btn-primary" style="display: contents">

Screenshot 7

This is the smallest fix I can find without having to install custom listeners. Worth it?

@fregante

Copy link
Copy Markdown
Member

I think there's a safer way:

  1. place the "draft" button after the primary button
  2. use flex to flip the order
  3. use .btn-primary:disabled + .btn {display: none}

This avoids any issues that come from using .btn-primary on a non-button.

@erenbati
erenbati marked this pull request as ready for review September 29, 2026 18:24
@erenbati

Copy link
Copy Markdown
Contributor Author

Implemented the safer approach you suggested: the Draft button now follows the primary button in the DOM, visual ordering is preserved with flex, and the Draft button is hidden via the adjacent-sibling rule while the primary button is disabled. No explicit upload listeners were added. CI is green on the current head. Marking this ready for re-review. Thanks!

@fregante fregante left a comment

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.

Also ensure that this still works on the gist creation page

Number(a.classList.contains('rgh-draft-pr-button'))
- Number(b.classList.contains('rgh-draft-pr-button')),
);
initialGroupedButtons.after(...buttons);

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.

Why do all this? The order is set in the initial query selector:

$$('.select-menu-item', initialGroupedButtons).toReversed()

}

.btn-primary:disabled + .rgh-draft-pr-button {
opacity: 0.5;

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.

Not identical to the real :disabled state but close enough"

Image Image

@fregante fregante changed the title one-click-pr-or-gist: disable draft button during upload one-click-pr-or-gist - Disable draft button during upload Sep 30, 2026
@fregante
fregante merged commit 90de5cd into refined-github:main Sep 30, 2026
14 checks passed
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.

one-click-pr-or-gist keeps "draft" button enabled during upload

2 participants