Implement STATE_DELTA for partial state updates#52
Merged
MarcosBrendonDePaula merged 2 commits intomainfrom Feb 12, 2026
Merged
Implement STATE_DELTA for partial state updates#52MarcosBrendonDePaula merged 2 commits intomainfrom
MarcosBrendonDePaula merged 2 commits intomainfrom
Conversation
Instead of sending the entire state object on every mutation, Live Components now emit STATE_DELTA with only the changed properties. This reduces WebSocket payload size and bandwidth usage, especially for components with large state objects. - Server proxy set trap: emits delta with single changed property - Server setState(): emits delta with partial updates - Client: merges STATE_DELTA into existing state via shallow merge - Full STATE_UPDATE preserved for mount/rehydrate scenarios https://claude.ai/code/session_01HB4ENmFebWTsco9UMa1z3D
16 tests covering: - Proxy set emits STATE_DELTA with only changed property - setState emits STATE_DELTA with partial updates (single message) - No emit when value is unchanged - Function updater form support - Internal state consistency after delta mutations - Action-driven state changes via proxy and setState - Message format (componentId, timestamp) https://claude.ai/code/session_01HB4ENmFebWTsco9UMa1z3D
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
This PR introduces a new
STATE_DELTAmessage type to optimize WebSocket payload size by sending only changed state properties instead of the full state object on every mutation.Key Changes
STATE_DELTAtoLiveMessageandWebSocketResponsetypes intypes.tsLiveComponentto emitSTATE_DELTAwith only the changed property instead of fullSTATE_UPDATEsetState()method to emitSTATE_DELTAcontaining only the properties that were actually modifiedSTATE_DELTAcase inuseLiveComponenthook to merge delta updates with existing stateImplementation Details
setState()emits a singleSTATE_DELTAmessage with all batch updates, reducing message count for multi-property changescomponentIdandtimestampfor proper routing and debugginghttps://claude.ai/code/session_01HB4ENmFebWTsco9UMa1z3D