Skip to content

Add onAfterSubmit timing demo for the feedback widget - #800

Open
tinsmith-dev[bot] wants to merge 3 commits into
mainfrom
tin/feedback-after-submit-demo
Open

tinsmith-dev[bot] wants to merge 3 commits into
mainfrom
tin/feedback-after-submit-demo

Conversation

@tinsmith-dev

@tinsmith-dev tinsmith-dev Bot commented Nov 8, 2026

Copy link
Copy Markdown

Why

#798 raised a concern worth settling with evidence rather than argument: onAfterSubmit only fires after the feedback POST resolves, so there's a real window where closing the tab (or navigating away) could lose the callback. This adds a runnable demo that makes that window visible and then proves what actually happens to it.

What's in it

packages/browser-sdk/example/feedback-after-submit-demo/ — a small app that opens the real feedback widget (built from this branch's src/, not a mock) against a local mock API with configurable artificial latency:

  1. Artificial latency control — widens the gap between submit and onAfterSubmit so it's easy to watch.
  2. Live widget — a banner stays red for as long as a feedback POST is pending, turns amber once the response is back but onAfterSubmit is still waiting on Send/close (by design), and green once the callback actually runs. A log shows exact timestamps for each step.
  3. Danger zone — fires the same feedback() call the widget's Send button makes, then navigates away before the response can arrive, simulating a closed tab. A persisted table cross-references the mock server's own receipt log (ground truth, independent of the tab) against whether any onAfterSubmit-equivalent callback ran client-side.

Confirmed findings from running it:

  • onAfterSubmit never fires once the tab is gone — guaranteed, every time, regardless of network speed. There's no way around this: the page that would run the callback no longer exists.
  • Separately, the SDK's feedback POST isn't sent with keepalive, so on a slower connection than localhost, the data itself (not just the callback) can be lost outright. The demo's keepalive checkbox (bypassing the SDK, since it doesn't expose that option) shows what addressing that half would look like.

See the demo's own README for how to run it and what to look at.

Notes for the reviewer

This only adds a new example directory — no changes to src/. It's independent of #798 (built here against current main); the same gap exists either way since #798 doesn't change the fundamental await-then-notify timing, only when the callback fires exactly once.

🤖 Generated with Claude Code

Adds a runnable demo that opens the real feedback widget against a local
mock API with configurable latency, to make visible the gap between a
user submitting feedback and onAfterSubmit firing. A "navigate away
mid-submit" scenario proves the callback never survives a closed tab,
and that the SDK's feedback POST isn't sent with `keepalive`.
- gone.html always redirects back to its own index page instead of a
  caller-supplied "return" URL, closing an open-redirect/XSS sink.
- server.mjs validates the requested delay with a strict range check
  instead of clamping, so CodeQL can see the timer duration is bounded.
Formatting-only (line wrap, import order); no behavior change.
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