Skip to content

Conversation

@anicioalexandre
Copy link
Collaborator

@anicioalexandre anicioalexandre commented Oct 2, 2025

  • design-system package update - v 1.1.2

    • Enhanced UI settings store to automatically load settings from client-side cookies when no initial settings are provided
  • authentication package update - v 5.0.4

    • Enhanced current profile store to automatically load profile from client-side cookies when no initial profile is provided
  • utils package update - v 4.0.3

    • Enhanced cookie store to automatically load cookies from client-side when no initial cookies are provided

Summary by CodeRabbit

  • New Features

    • Automatically load the current profile from browser cookies when none is provided.
    • UI settings now auto-load from cookies and persist updates, ensuring preferences (e.g., theme) apply consistently.
    • Improved client-side cookie handling for more reliable defaults.
  • Chores

    • Updated internal dependencies across packages for compatibility and stability.
    • Version bumps for authentication, components, design-system, graphql, provider, utils, and wagtail packages.
  • Documentation

    • Changelogs updated to reflect the above enhancements and dependency updates.

@changeset-bot
Copy link

changeset-bot bot commented Oct 2, 2025

⚠️ No Changeset found

Latest commit: 7a1ae31

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Oct 2, 2025

Walkthrough

Introduces 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

Cohort / File(s) Summary
Authentication: Current Profile Store
packages/authentication/modules/profile/useCurrentProfile/store.ts
Adds client cookie fallback via getClientSideCurrentProfile, makes initialProfile optional in createProfileStore, initializes from cookie when absent, adds updateProfileIfActive to conditionally update state/cookies, simplifies initialization flow.
Design System: UI Settings Hook & Store
packages/design-system/hooks/web/useUISettings/index.tsx, packages/design-system/hooks/web/useUISettings/store.ts
Introduces getClientSideUISettings to derive initial settings from cookies/defaults; makes initialSettings optional; adds getSettingsStore, getUISettingsFromStore, setUISettingsInStore, resetSettingsStore; removes explicit DEFAULT fallback in hook, relying on store initialization.
Utils: Cookie Store
packages/utils/hooks/useCookie/store.ts
Adds client-side cookie reader (js-cookie) and fallback when initialCookies is not provided; initializes store with derived cookies; existing set/remove behavior retained.
Version Bumps: package.json
packages/authentication/package.json, packages/components/package.json, packages/design-system/package.json, packages/graphql/package.json, packages/provider/package.json, packages/utils/package.json, packages/wagtail/package.json
Increments package versions to reflect patch releases; no functional changes in manifests.
Changelogs
packages/authentication/CHANGELOG.md, packages/components/CHANGELOG.md, packages/design-system/CHANGELOG.md, packages/graphql/CHANGELOG.md, packages/provider/CHANGELOG.md, packages/utils/CHANGELOG.md, packages/wagtail/CHANGELOG.md
Documents new patch versions and dependency updates; notes client-side cookie-based initialization in authentication, design-system, and utils.

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
Loading
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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • BA-2560: fix tests #268: Adjusts test providers to pass explicit initialProfile/null and updates cookie hook imports, aligning with the new optional initialProfile and cookie fallback behavior.

Suggested labels

needs review

Suggested reviewers

  • priscilladeroode
  • deboracosilveira

Poem

A nibble of cookies, a hop through the night,
Stores wake from crumbs with settings set right.
Profiles peek out, “Is my ID still true?”
If yes, we persist—if not, we shoo.
Patch bumps abound—thump-thump, delight!
Rabbit-approved flows, tidy and light. 🐇🍪

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description follows the general template format but omits several updated packages and leaves out dependency update details for the design-system and authentication packages, so it does not document all required changelog items. Please update the description to include all package updates present in this PR (components, graphql, provider, wagtail) and add missing changelog entries for dependency updates under the design-system and authentication sections.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title concisely summarizes the main intent of the changes by referencing the ticket and indicating that client cookies will be loaded as initial data, which aligns with the core updates across packages.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/BA-2778-client-cookies-as-initial-data

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 2, 2025

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between bc7ddf6 and 7a1ae31.

📒 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.4 and @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 initializeCookieStore function correctly delegates to createCookieStore with the optional initialCookies parameter, and the store recreation logic remains sound.


15-34: Acknowledge in-memory store behavior
The setCookie/removeCookie methods in createCookieStore correctly only update the in-memory state—persistence to browser cookies is handled by higher-level functions (e.g. ClientCookies.set/ClientCookies.remove in packages/utils/functions/cookie). No changes required here.


1-13: Client-only guard confirmed
Imports of useCookie/store.ts appear only in packages/utils/functions/cookie/index.ts, which begins with a 'use client' directive, so js-cookie won’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 createProfileStore function correctly implements the client-side fallback pattern. The new updateProfileIfActive method 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 initializeProfileStore function correctly delegates to createProfileStore with the optional initialProfile parameter. The control flow is clean and follows the established pattern.


77-80: LGTM! New helper export for conditional updates.

The new updateProfileIfActiveInStore export correctly delegates to the store's updateProfileIfActive method, 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_SETTINGS import is correct, as the default settings are now handled internally by getClientSideUISettings in store.ts. This improves separation of concerns.


38-38: LGTM! Initialization delegates fallback logic to store.

The change to pass initialUISettings directly to initializeSettingsStore correctly delegates the fallback logic to the store's getClientSideUISettings function, 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 createSettingsStore function correctly uses getClientSideUISettings to 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 initializeSettingsStore function correctly accepts optional initialSettings and delegates to createSettingsStore. The recreation logic is simplified compared to cookie and profile stores, which is appropriate since UI settings are always derived from defaults and cookies via getClientSideUISettings.


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 merges DEFAULT_UI_SETTINGSinitialSettings → 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 from js-cookie.

@anicioalexandre anicioalexandre merged commit 171f751 into master Oct 6, 2025
8 checks passed
@anicioalexandre anicioalexandre deleted the feature/BA-2778-client-cookies-as-initial-data branch October 6, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants