fix: ThemeSettingsStore singleton via React Context#441
Conversation
Previously useThemeSettingsStore() created a new store instance on every call. Now the store is created once in withWeaverse() via useRef, provided through React Context, and synced with route data changes via useEffect. - Split into useCreateThemeSettingsStore (provider) and useThemeSettingsStore (consumer) - Fallback path preserved for older themes not yet using withWeaverse(Layout) - Added unit tests for update sync behavior and constructor edge cases
|
Claude finished @paul-phan's task in 3m 38s —— View job Code Review SummaryOverall: This PR is ready to merge. The fix properly addresses the singleton pattern bug using correct React patterns (Context + useRef + useEffect), maintains backward compatibility, and includes good test coverage. The code follows AGENTS.md conventions and has no blocking issues. Issues🔴 None found — No blocking issues identified. Suggestions🟡 packages/hydrogen/src/utils/use-theme-settings-store.ts:137 — The non-null assertion // Current code - correct but implicit
const store = fromContext ?? fallbackRef.current!
// More explicit alternative
const store = fromContext ?? fallbackRef.current ?? (() => {
const s = new ThemeSettingsStore(data?.weaverseTheme)
fallbackRef.current = s
return s
})()This makes it crystal clear that 💬 packages/hydrogen/src/utils/use-theme-settings-store.ts:110 — The removed comment What's Good
Agent Fix Prompts
🟡 Make null safety explicit 💬 Restore useful comment |
Summary
useThemeSettingsStore()call, causing duplicate stores and state divergenceuseCreateThemeSettingsStore(provider-side, creates singleton viauseRef) anduseThemeSettingsStore(consumer-side, reads from React Context)useEffectinstead of during render (fixes "Cannot update component while rendering" React warning)withWeaverse(App)instead ofwithWeaverse(Layout)Test plan