Skip to content

Fix Passkey buttons not triggering sometimes#2748

Merged
monorkin merged 1 commit intomainfrom
fix-passkey-buttons-not-triggering-sometimes
Mar 24, 2026
Merged

Fix Passkey buttons not triggering sometimes#2748
monorkin merged 1 commit intomainfrom
fix-passkey-buttons-not-triggering-sometimes

Conversation

@monorkin
Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings March 24, 2026 13:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the global Passkey JavaScript companion to make passkey button clicks and conditional-mediation sign-in more reliable across Turbo navigation and dynamically inserted DOM.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Changes:

  • Replaces per-button click bindings with a single delegated document click handler for [data-passkey].
  • Ensures transient UI state is reset on turbo:before-cache (re-enables disabled passkey buttons, clears error state).
  • Triggers conditional mediation when a matching form appears using a MutationObserver + WeakSet guard.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +65 to +71
new MutationObserver((mutations) => {
for (const { addedNodes } of mutations) {
for (const node of addedNodes) {
if (node.nodeType === Node.ELEMENT_NODE) mediateIn(node)
}

attemptConditionalMediation()
}
}
}).observe(document.documentElement, { childList: true, subtree: true })
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

passkey.js is imported globally (via app/javascript/application.js), so this MutationObserver will observe the entire document subtree on every page. That can add overhead on pages that will never render passkey conditional-mediation forms. Consider gating observer setup (or its callback work) behind a cheap precondition like presence of the passkey request-options meta tag / conditional mediation API support, so most pages avoid the observer entirely.

Copilot uses AI. Check for mistakes.
@monorkin monorkin merged commit 1f63589 into main Mar 24, 2026
17 checks passed
@monorkin monorkin deleted the fix-passkey-buttons-not-triggering-sometimes branch March 24, 2026 13:51
@monorkin monorkin mentioned this pull request Mar 30, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants