-
Notifications
You must be signed in to change notification settings - Fork 2
BA-2778: load client cookies as initial data #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BA-2778: load client cookies as initial data #295
Conversation
|
WalkthroughIntroduces client-side cookie fallbacks for initializing profile, UI settings, and cookie stores. Makes initial parameters optional, adds helpers to read cookies on the client, and adds store accessors for UI settings. Updates related package versions and changelogs across multiple packages. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor App
participant Provider as CurrentProfileProvider
participant Store as Profile Store
participant Cookies
App->>Provider: Mount with optional initialProfile
Provider->>Store: createProfileStore(initialProfile?)
Note over Store: If no initialProfile,<br/>read from client cookies
Store->>Cookies: getClientSideCurrentProfile()
Cookies-->>Store: profile or null
Store-->>Provider: initialized state (profile|null)
rect rgba(200,255,200,0.2)
Note over App,Store: Conditional profile update
App->>Store: updateProfileIfActive(updatedProfile)
Store->>Store: Check activeProfileId match
alt IDs match
Store->>Cookies: persist profile cookie
Store-->>App: state updated
else IDs differ
Store-->>App: no-op
end
end
sequenceDiagram
autonumber
actor App
participant Hook as useUISettings
participant Store as UISettings Store
participant Cookies
participant Theme as Theme Manager
App->>Hook: useUISettings(initialSettings?)
Hook->>Store: initializeSettingsStore(initialSettings?)
Note over Store: Derive initial via DEFAULTS + cookies + provided
Store->>Cookies: getClientSideUISettings()
Cookies-->>Store: settings (merged or defaults)
Store-->>Hook: store ready
rect rgba(200,200,255,0.2)
Hook->>Store: setUISettingsInStore(partial)
Store->>Cookies: persist settings
Store->>Theme: apply mode if changed
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (18)
packages/authentication/CHANGELOG.md(1 hunks)packages/authentication/modules/profile/useCurrentProfile/store.ts(2 hunks)packages/authentication/package.json(1 hunks)packages/components/CHANGELOG.md(1 hunks)packages/components/package.json(1 hunks)packages/design-system/CHANGELOG.md(1 hunks)packages/design-system/hooks/web/useUISettings/index.tsx(2 hunks)packages/design-system/hooks/web/useUISettings/store.ts(3 hunks)packages/design-system/package.json(1 hunks)packages/graphql/CHANGELOG.md(1 hunks)packages/graphql/package.json(1 hunks)packages/provider/CHANGELOG.md(1 hunks)packages/provider/package.json(1 hunks)packages/utils/CHANGELOG.md(1 hunks)packages/utils/hooks/useCookie/store.ts(2 hunks)packages/utils/package.json(1 hunks)packages/wagtail/CHANGELOG.md(1 hunks)packages/wagtail/package.json(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
packages/utils/hooks/useCookie/store.ts (1)
packages/utils/hooks/useCookie/types.ts (2)
CookieState(18-18)BaseCookies(5-7)
packages/authentication/modules/profile/useCurrentProfile/store.ts (3)
packages/authentication/types/profile.ts (1)
MinimalProfile(1-6)packages/authentication/modules/profile/useCurrentProfile/constants.ts (1)
CURRENT_PROFILE_KEY_NAME(1-1)packages/authentication/modules/profile/useCurrentProfile/types.ts (1)
CurrentProfileState(9-13)
packages/design-system/hooks/web/useUISettings/index.tsx (1)
packages/design-system/hooks/web/useUISettings/store.ts (1)
initializeSettingsStore(51-63)
packages/design-system/hooks/web/useUISettings/store.ts (1)
packages/design-system/hooks/web/useUISettings/constants.ts (2)
UI_SETTINGS_KEY_NAME(3-3)DEFAULT_UI_SETTINGS(5-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (javascript)
🔇 Additional comments (16)
packages/components/package.json (1)
4-4: Version bump looks good.1.4.4 aligns with the release train for this package—no concerns.
packages/graphql/CHANGELOG.md (1)
3-9: LGTM!The changelog entry correctly documents the dependency updates to
@baseapp-frontend/authentication@5.0.4and@baseapp-frontend/utils@4.0.3, which align with the PR's objective of introducing client-side cookie fallback initialization.packages/components/CHANGELOG.md (1)
3-12: LGTM!The changelog entry accurately reflects the dependency updates that support the client-side cookie fallback initialization introduced in this PR.
packages/utils/hooks/useCookie/store.ts (3)
36-49: LGTM!The
initializeCookieStorefunction correctly delegates tocreateCookieStorewith the optionalinitialCookiesparameter, and the store recreation logic remains sound.
15-34: Acknowledge in-memory store behavior
ThesetCookie/removeCookiemethods increateCookieStorecorrectly only update the in-memory state—persistence to browser cookies is handled by higher-level functions (e.g.ClientCookies.set/ClientCookies.removeinpackages/utils/functions/cookie). No changes required here.
1-13: Client-only guard confirmed
Imports ofuseCookie/store.tsappear only inpackages/utils/functions/cookie/index.ts, which begins with a'use client'directive, sojs-cookiewon’t run during SSR.packages/authentication/modules/profile/useCurrentProfile/store.ts (3)
22-44: LGTM! Client-side fallback and conditional update logic are well-implemented.The
createProfileStorefunction correctly implements the client-side fallback pattern. The newupdateProfileIfActivemethod is a good practice, ensuring that profile updates only occur when the active profile ID matches, preventing stale or incorrect updates.
46-59: LGTM!The
initializeProfileStorefunction correctly delegates tocreateProfileStorewith the optionalinitialProfileparameter. The control flow is clean and follows the established pattern.
77-80: LGTM! New helper export for conditional updates.The new
updateProfileIfActiveInStoreexport correctly delegates to the store'supdateProfileIfActivemethod, providing a clean API for external code to perform conditional profile updates.packages/design-system/CHANGELOG.md (1)
3-10: LGTM!The changelog entry accurately documents the enhancement to the UI settings store to automatically load settings from client-side cookies when no initial settings are provided, and correctly notes the dependency update to
@baseapp-frontend/utils@4.0.3.packages/design-system/hooks/web/useUISettings/index.tsx (2)
8-8: LGTM! Import cleanup aligns with store refactoring.The removal of
DEFAULT_UI_SETTINGSimport is correct, as the default settings are now handled internally bygetClientSideUISettingsinstore.ts. This improves separation of concerns.
38-38: LGTM! Initialization delegates fallback logic to store.The change to pass
initialUISettingsdirectly toinitializeSettingsStorecorrectly delegates the fallback logic to the store'sgetClientSideUISettingsfunction, simplifying the provider's responsibilities.packages/design-system/hooks/web/useUISettings/store.ts (4)
34-49: LGTM! Store initialization and persistence are well-implemented.The
createSettingsStorefunction correctly usesgetClientSideUISettingsto derive initial settings and implements persistence to cookies on every settings update. The theme mode handler ensures the DOM reflects the current theme.
51-63: LGTM! Simplified store recreation logic is appropriate for UI settings.The
initializeSettingsStorefunction correctly accepts optionalinitialSettingsand delegates tocreateSettingsStore. The recreation logic is simplified compared to cookie and profile stores, which is appropriate since UI settings are always derived from defaults and cookies viagetClientSideUISettings.
64-84: resetSettingsStore behavior is correct
resetSettingsStore intentionally only nulls the in-memory store—consistent with other reset helpers; persistent cookies remain by design, and should be cleared explicitly via Cookies.remove when needed.
20-32: Approve getClientSideUISettings merge logic and error handling
Correctly mergesDEFAULT_UI_SETTINGS→initialSettings→ stored cookies with safe fallback on JSON parse errors. Ensure this helper only runs in browser contexts (e.g. add'use client'at the top of the module or guard all consumers) to avoid runtime errors fromjs-cookie.



design-systempackage update -v 1.1.2authenticationpackage update -v 5.0.4utilspackage update -v 4.0.3Summary by CodeRabbit
New Features
Chores
Documentation