Skip to content

feat(vite): auto-inject browser client connect script#7

Merged
kevinccbsg merged 7 commits intomainfrom
feat/auto-connect
May 8, 2026
Merged

feat(vite): auto-inject browser client connect script#7
kevinccbsg merged 7 commits intomainfrom
feat/auto-connect

Conversation

@kevinccbsg
Copy link
Copy Markdown
Member

Summary

  • twdRemote() Vite plugin now auto-injects a <script type="module"> into dev index.html that imports createBrowserClient from twd-relay/browser and calls .connect(). Vite consumers no longer need a manual createBrowserClient block in their entry file.
  • New autoConnect option: true (default), false (opt out), or an AutoConnectOptions object to forward reconnect/reconnectInterval/log/maxTestDurationMs into the injected client.
  • Manual createBrowserClient API unchanged — still public for Webpack/Angular/Rollup/esbuild/Rspack and for users opting out of auto-inject.
  • Plugin is apply: 'serve', so production builds are untouched.
  • examples/twd-test-app updated to drop its manual block.

Spec: docs/superpowers/specs/2026-05-08-relay-auto-connect-design.md
Plan: docs/superpowers/plans/2026-05-08-relay-auto-connect.md

Migration note for existing Vite consumers

After upgrade, you have three options — pick exactly one:

  1. Recommended: delete the manual createBrowserClient(...).connect() block from main.tsx (or equivalent). End state: zero dev-only relay setup in your entry file.
  2. No-op: set autoConnect: false on the plugin call. Behavior identical to today.
  3. Don't do bothautoConnect: true (default) plus a manual call connects two clients. The relay logs will show the duplicate.

Non-Vite consumers: nothing changes.

Test plan

  • Unit tests pass: npm test -- --run → 73/73 (15 in the vite plugin file: 6 existing + 9 new).
  • Manual smoke (browser-level):
    • npm run build && cd examples/twd-test-app && npm run dev — page loads, DevTools → Network → WS shows a connection to /__twd/ws, the [TWD] title prefix appears, and npx twd-relay run triggers a real run.
    • Set autoConnect: false in vite.config.ts and restore the manual createBrowserClient block in main.tsx — confirm behavior is identical to before this PR (one client connects). Then revert.
    • Set a non-default Vite base (e.g. /my-app/) — confirm the relay listens at /my-app/__twd/ws and the injected script connects there too.

🤖 Generated with Claude Code

@kevinccbsg kevinccbsg merged commit a290607 into main May 8, 2026
5 checks passed
@kevinccbsg kevinccbsg deleted the feat/auto-connect branch May 8, 2026 20:25
kevinccbsg added a commit that referenced this pull request May 8, 2026
Features since 1.1.1:
- end-of-run failures recap (#6)
- twdRemote() auto-connect: plugin auto-injects browser client (#7)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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