Skip to content

fix(core): allow ctx.rpc.sharedState access during plugin setup#195

Merged
antfu merged 2 commits intomainfrom
antfu/fix-rpc-shared-state-timing
Mar 12, 2026
Merged

fix(core): allow ctx.rpc.sharedState access during plugin setup#195
antfu merged 2 commits intomainfrom
antfu/fix-rpc-shared-state-timing

Conversation

@antfu
Copy link
Member

@antfu antfu commented Mar 11, 2026

Description

Allow plugins to safely call ctx.rpc.sharedState during their setup function without triggering timing errors. The broadcast() method now silently returns when _rpcGroup is not yet initialized, since no WebSocket clients can be connected before the WS server starts. This fixes the "RpcGroup is not set" error that occurred when plugins accessed shared state during setup.

Linked Issues

Fixes the internal timing issue reported in plugin usage patterns.

Additional context

The fix ensures that early broadcasts are safely ignored during plugin initialization, as they are guaranteed to have zero connected clients. This allows developers to use the RPC shared state API in plugin setup functions as intended.

Allow plugins to safely call ctx.rpc.sharedState during setup without errors.
The broadcast() method now silently returns when _rpcGroup is not yet initialized,
since no WebSocket clients can be connected before the WS server starts. This
fixes the timing issue where shared state mutations would throw "RpcGroup is not set"
during early plugin initialization.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@vitejs/devtools@195
npm i https://pkg.pr.new/@vitejs/devtools-kit@195
npm i https://pkg.pr.new/@vitejs/devtools-rolldown@195
npm i https://pkg.pr.new/@vitejs/devtools-rpc@195

commit: 97f83e4

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@antfu antfu merged commit 39b11d8 into main Mar 12, 2026
9 checks passed
@antfu antfu deleted the antfu/fix-rpc-shared-state-timing branch March 12, 2026 00:28
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