fix: flatten providers for large state trees

Merged
HA
2d ago
+373-224

Closes #7429

Summary

Flatten the state provider tree on both the client and server. A single shared state-store context keeps provider depth independent of the number of substates, including during development SSR.

Generated state reads subscribe to their substate with useSyncExternalStore. A delta applies immutably to only that substate and notifies only its subscribers, avoiding a full state-map copy or rebuilding all provider elements on every update. The external-store hook gives React consistent snapshots during concurrent rendering; the store is changed only by event dispatch, never during render.

Testing

  • Focused context, compiler, memoization, and component tests: 361 passed, 1 skipped, 1 excluded because the local environment lacks the optional Plotly dependency.
  • Includes a Node runtime test that traverses an SSR tree with 5,000 substates and a client test that verifies targeted notification and unchanged-state identity.
  • Focused Ruff checks and git diff --check passed.