Skip to content

fix(185000): never throw on invalid stored tour/tooltip selectors - #172

Merged
boehlerlukas merged 1 commit into
masterfrom
gleap/185000-tour-selector-validation
Oct 9, 2026
Merged

boehlerlukas merged 1 commit into
masterfrom
gleap/185000-tour-selector-validation

Conversation

@boehlerlukas

Copy link
Copy Markdown
Contributor

Gleap ticket #185000.

Problem

A tour step selector typed without brackets (data-x="y" instead of [data-x="y"]) makes document.querySelector throw. In GleapTours.highlight the catch retried with the colon-escaped form, which threw again inside the retry timer, so the tour died with an uncaught error instead of ending through onElementNotFound. Same class of bug elsewhere:

  • Copilot tours waitForElement: the throw inside setInterval repeated every 100 ms forever and the promise never settled.
  • Tooltips: node.matches(selector) in the MutationObserver threw on every DOM mutation.
  • Builder highlight-element / click messages.

Fix

New GleapSafeSelector (querySelectorSafe, querySelectorAllSafe, matchesSelectorSafe): tries the stored selector, then the bracketed attribute form, then the colon-escaped id form; anything still invalid resolves to nothing (one console.warn per selector). Used in tours, copilot tours, tooltips and the admin bridge. Existing tours with a bare attribute selector now find their element.

Companion editor validation: GleapSDK/Frontend (same branch name).

Verified

  • npm test: 521/521 pass; npm run build succeeds (build/published artifacts left to the release).
  • Throwaway jsdom check: bare/quoted/unquoted attribute selectors resolve, #a:b still resolves, div[[[ → null; a tour with div[[[ ends via onElementNotFound without throwing; a tour with data-pf="…" highlights the element.

🤖 Generated with Claude Code

A selector typed without brackets (data-x="y") made querySelector throw
in the tour highlight; the colon-escape fallback in the catch threw again,
so the tour died in its retry timer instead of ending via
onElementNotFound. Copilot tours polled forever, tooltip matching threw on
every DOM mutation and the builder's highlight/click messages threw too.

GleapSafeSelector tries the stored selector, then the bracketed attribute
form, then the colon-escaped id form, and resolves to nothing otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@boehlerlukas
boehlerlukas merged commit 5c2f45e into master Oct 9, 2026
1 check passed
@boehlerlukas boehlerlukas mentioned this pull request Oct 9, 2026
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.

1 participant