Consume preferences from the subscribe_events initial_state snapshot#853
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the app-shell event subscription flow to consume user preferences from the subscribe_events initial_state snapshot, applying theme immediately from the snapshot and exposing a prefsLoaded context flag so consumers can gate preference-dependent UI without waiting for a separate preferences fetch.
Changes:
- Add
preferences: UserPreferencestosubscribe_events.initial_statetyping and handle it in theINITIAL_STATEevent handler (apply theme + set_prefsLoaded). - Introduce
prefsLoadedContextand provide it fromESPHomeApp. - Update theme-preference loading to stop re-applying theme from
config/get_preferences, and add a unit test covering the new initial-state behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/components/app-shell/events-initial-state-prefs.test.ts | Adds coverage ensuring INITIAL_STATE applies theme from snapshot and sets _prefsLoaded. |
| src/context/index.ts | Re-exports the new prefsLoadedContext. |
| src/context/contexts.ts | Defines prefsLoadedContext for preference-snapshot readiness. |
| src/components/app-shell/events.ts | Seeds theme + _prefsLoaded from INITIAL_STATE.preferences. |
| src/components/app-shell/data-load.ts | Stops applying theme from getPreferences() (now only updates expert mode). |
| src/components/app-shell.ts | Provides _prefsLoaded via prefsLoadedContext from the app shell. |
| src/api/types/event-subscription.ts | Extends InitialStateEventData to include a preferences snapshot. |
PR Review — Consume preferences from the subscribe_events initial_state snapshotClean, well-scoped change that consumes preferences from the Strengths:
Needs attention (non-blocking):
Checklist
Automated review by Kōan (Claude) |
esphbot
left a comment
There was a problem hiding this comment.
No blocking issues found.
|
Suggestion #2 (the Suggestion #1 ( |
What does this implement/fix?
Frontend half of the preferences-in-initial-state plumbing; companion to esphome/device-builder#1479. The preferences snapshot now arrives on the
subscribe_eventsinitial_statepush, so the app shell applies theme straight from it and sets aprefsLoadedflag rather than waiting on a separateconfig/get_preferencesround trip. Expert mode keeps loading the way it does today; there are no experience-level changes here, that lands on top in a follow up.Related issue or feature (if applicable):
Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesChecklist
npm run lintpasses.npm run testpasses.