Skip to content

Meta: Prepare options page to allow multiple tokens - #8851

Closed
fregante with Copilot wants to merge 13 commits into
mainfrom
copilot/extract-token-ui-component
Closed

fregante with Copilot wants to merge 13 commits into
mainfrom
copilot/extract-token-ui-component

Conversation

Copilot AI commented Jan 5, 2026 •

Copy link
Copy Markdown
Contributor

Extracted token input UI from options.html and token-validation.tsx into dedicated Svelte 5 custom elements for better encapsulation and reusability.

Changes

  • Created source/options/rgh-token.svelte: Custom element encapsulating token input, validation, and scope display using idiomatic Svelte 5 patterns:

    • $props() for component properties
    • $state() for reactive state
    • SvelteMap for reactive scope tracking
    • onMount() for initialization
    • Component-scoped styles for password masking, layout, and monospace font (inline styles from webext-base-css)
    • Shadow DOM form participation enabled using formAssociated = true and ElementInternals API
    • ElementInternals properly initialized in constructor for correct form element access (form.elements.personalToken)
    • Exposes name, type, form, validity, value (getter + setter with pending queue), and disabled for full form control compatibility
    • Value setter with pending value queue mechanism to handle race conditions when webext-options-sync sets values before shadow DOM is initialized
    • Pending values are stored in _pendingValue and applied in onMount() once component is fully ready
    • Input field properly syncs with form via setFormValue()
  • Created source/options/token-scope.svelte: Sub-component for individual scope list items:

    • name prop for scope identifier (e.g., "workflow", "repo")
    • state prop for validation state ("valid", "invalid", or empty)
    • Slot for scope description content
    • Component-scoped styles for validation icons (gray circle, green checkmark, red X)
    • All data-validation selector styles moved from global CSS to component
    • Improves code organization and component composition
  • Updated source/options.html:

    • Replaced inline markup with <rgh-token> element
    • Added name="personalToken" attribute to custom element for form participation
    • Added script tag for token-scope component
  • Simplified source/options/token-validation.tsx: Removed validation logic (now in component), kept only synced form integration

  • Updated source/options.css: Removed all token-specific styles (moved to components):

    • Password masking style (-webkit-text-security)
    • List reset styles for token component
    • Margin styles for token component elements
    • All data-validation selector styles with validation icons
  • Updated rollup.config.js: Added both components to build inputs

  • Improved token validation:

    • Removed expiration date display from success message (now shows only 👤 @username)
    • Expired tokens are immediately detected and shown as invalid with "Token expired" message
    • All token validation errors now show "(expired?)" hint to help users identify the issue
  • Full webext-options-sync compatibility with early initialization support:

    • Added validity, value (getter), and disabled getters for form parsing (read)
    • Added value setter with pending value queue for bidirectional value synchronization (write)
    • Handles race condition where webext-options-sync sets values before shadow DOM is fully initialized
    • Values set before mount are queued in _pendingValue and applied in onMount()
    • Setter updates internal input, syncs with ElementInternals, and triggers validation
    • Fixes "Cannot read properties of undefined (reading 'valid')" error
    • Enables webext-options-sync to both read and write token values regardless of initialization timing

Test URLs

Local testing with HTTP server (Chrome extension APIs unavailable in standalone browser)

Screenshot

Component with validation error and "(expired?)" hint:

Component with password masking (blur):

Original prompt

Extract token UI from options.html and token-validation.tsx into dedicated svelte custom component:

Make it idiomatic svelte 5

This is the starting markup:






  • The token enables some features to read data from public repositories
  • The public_repo scope lets them edit your public repositories
  • The repo scope lets them edit private repositories as well
  • The read:project scope lets them determine if a repo/org uses projects
  • The workflow scope lets them edit workflow files .github/workflows/*.yml


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Extract token UI into dedicated Svelte component Extract token UI into Svelte 5 custom component Jan 5, 2026
Copilot AI requested a review from fregante January 5, 2026 09:27
Comment thread source/options/rgh-token.svelte Resolved
Copilot AI changed the title Extract token UI into Svelte 5 custom component Extract token UI into Svelte 5 custom components Jan 6, 2026
Copilot AI requested a review from fregante January 6, 2026 07:36
@fregante

fregante commented Jan 6, 2026

Copy link
Copy Markdown
Member

@copilot

  • options.css has some style that needs to be moved to the component
  • also remove the "expired" state from the token because expired tokens are equal to "invalid". Maybe add (expired?) to the failure message

@fregante
fregante marked this pull request as ready for review January 6, 2026 08:09
@fregante fregante added the meta Related to Refined GitHub itself label Jan 6, 2026

Copilot AI commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

  • options.css has some style that needs to be moved to the component
  • also remove the "expired" state from the token because expired tokens are equal to "invalid". Maybe add (expired?) to...

Moved token-specific styles from options.css to the component's <style> section. Also removed the expiration date display from the success message and added "(expired?)" hint to 401/403 error messages. Expired tokens are now treated as invalid immediately.

Commit: 830aba9

Screenshot showing updated component

Screenshot showing password masking

Comment thread source/options.css Resolved
Comment thread source/options/rgh-token.svelte Resolved
Copilot AI requested a review from fregante January 6, 2026 12:51
@fregante

fregante commented Jan 9, 2026

Copy link
Copy Markdown
Member

@copilot

The field is not "Associated to the form" because it's inside the shadow dom. How to fix this in svelte? I found this for more info https://www.hjorthhansen.dev/shadow-dom-form-participation/

This style is not available in the shadow dom, add it

.monospace-field {
	/* Same as GitHub style for `code` */
	font-family:
		ui-monospace,
		SFMono-Regular,
		'SF Mono',
		Menlo,
		Consolas,
		'Liberation Mono',
		monospace !important;
}

Copilot AI requested a review from fregante January 9, 2026 12:14
@fregante

fregante commented Jan 9, 2026

Copy link
Copy Markdown
Member

@copilot the @import is not evaluated. Is the build missing something?
The field is still not attached to the form

Copilot AI commented Jan 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the @import is not evaluated. Is the build missing something?
The field is still not attached to the form

Fixed both issues:

  1. CSS import: Replaced @import with inline styles from webext-base.css. CSS @import doesn't work in Svelte shadow DOM styles, so I copied the .monospace-field definition directly into the component styles.

  2. Form participation: Added name="personalToken" attribute to the <rgh-token> element in options.html and exposed name, type, and form getters in the custom element class. The field now properly attaches to the form and is accessible via document.querySelector('form').elements.personalToken.

Commit: ed3aec3

@fregante

Copy link
Copy Markdown
Member

@copilot

webext-options-sync.js:217 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'valid')
    at OptionsSync._parseForm (webext-options-sync.js:217:32)
    at OptionsSync._updateForm (webext-options-sync.js:203:39)
    at OptionsSync.syncForm (webext-options-sync.js:74:14)
    at async OptionsSyncPerDomain.syncForm (webext-options-sync-per-domain.js:77:9)
    at async generateDom (options.js:110:15)
    at async init (options.js:177:2)

Copilot AI commented Jan 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

webext-options-sync.js:217 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'valid')

...

Fixed by adding validity, value, and disabled getters to the custom element class. These getters delegate to the internal input field in the shadow DOM, making the custom element compatible with webext-options-sync's form parsing logic that expects these properties.

Commit: 35febae

@fregante

Copy link
Copy Markdown
Member

:woot: it's working! Except that webext-options-sync is unable to set the value. It can read it but not write it 🤔

@copilot ?

Copilot AI commented Jan 10, 2026

Copy link
Copy Markdown
Contributor Author

:woot: it's working! Except that webext-options-sync is unable to set the value. It can read it but not write it 🤔

@copilot ?

Fixed by adding a value setter to the custom element class. The setter:

  1. Updates the internal input field's value
  2. Syncs with ElementInternals via setFormValue()
  3. Triggers an input event to activate validation

This enables webext-options-sync to both read and write the token value.

Commit: b420f98

@fregante

Copy link
Copy Markdown
Member

@copilot unchanged. The value can be read from the field but it's not set

Copilot AI commented Jan 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot unchanged. The value can be read from the field but it's not set

Fixed by adding a pending value queue mechanism. The issue was a race condition: webext-options-sync was setting the value before the shadow DOM was fully initialized.

The fix:

  1. Added _pendingValue property to store values set before mount
  2. Value setter checks if shadow DOM input exists; if not, stores in _pendingValue
  3. In onMount(), applies any pending value to the input field
  4. Value getter returns pending value as fallback if input doesn't exist yet

This handles the timing issue where webext-options-sync initializes form values before Svelte components are fully mounted.

Commit: 07418c3

@fregante
fregante marked this pull request as draft January 10, 2026 09:18
@fregante fregante changed the title Extract token UI into Svelte 5 custom components Meta: Prepare options page to allow multiple tokens Jan 10, 2026
@fregante

Copy link
Copy Markdown
Member

@fregante

Copy link
Copy Markdown
Member

The last commits just change stuff without fixing anything. Not sure why it's not working, someone needs to look into the deserializer and see what method is failing to set the value.

@fregante fregante closed this Mar 10, 2026
@fregante
fregante deleted the copilot/extract-token-ui-component branch March 10, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Related to Refined GitHub itself

Development

Successfully merging this pull request may close these issues.

2 participants