feat(vite): auto-inject browser client connect script#7
Merged
kevinccbsg merged 7 commits intomainfrom May 8, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ngle site) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
twdRemote()Vite plugin now auto-injects a<script type="module">into devindex.htmlthat importscreateBrowserClientfromtwd-relay/browserand calls.connect(). Vite consumers no longer need a manualcreateBrowserClientblock in their entry file.autoConnectoption:true(default),false(opt out), or anAutoConnectOptionsobject to forwardreconnect/reconnectInterval/log/maxTestDurationMsinto the injected client.createBrowserClientAPI unchanged — still public for Webpack/Angular/Rollup/esbuild/Rspack and for users opting out of auto-inject.apply: 'serve', so production builds are untouched.examples/twd-test-appupdated to drop its manual block.Spec:
docs/superpowers/specs/2026-05-08-relay-auto-connect-design.mdPlan:
docs/superpowers/plans/2026-05-08-relay-auto-connect.mdMigration note for existing Vite consumers
After upgrade, you have three options — pick exactly one:
createBrowserClient(...).connect()block frommain.tsx(or equivalent). End state: zero dev-only relay setup in your entry file.autoConnect: falseon the plugin call. Behavior identical to today.autoConnect: true(default) plus a manual call connects two clients. The relay logs will show the duplicate.Non-Vite consumers: nothing changes.
Test plan
npm test -- --run→ 73/73 (15 in the vite plugin file: 6 existing + 9 new).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, andnpx twd-relay runtriggers a real run.autoConnect: falseinvite.config.tsand restore the manualcreateBrowserClientblock inmain.tsx— confirm behavior is identical to before this PR (one client connects). Then revert.base(e.g./my-app/) — confirm the relay listens at/my-app/__twd/wsand the injected script connects there too.🤖 Generated with Claude Code