Skip to content

feat(core): init useLocalizationConfig only when localization.enabled is true - #3216

Merged
lemagnetic merged 1 commit into
feat/multilanguagefrom
feat/conditional-localization-config
Feb 23, 2026
Merged

lemagnetic merged 1 commit into
feat/multilanguagefrom
feat/conditional-localization-config

Conversation

@lemagnetic

@lemagnetic lemagnetic commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

Stores with localization disabled (localization.enabled: false) in discovery config were still initializing the useLocalizationConfig hook, which accesses config.localization.locales and could cause unnecessary behavior or errors. The goal is to initialize this hook only when the localization feature is enabled in discovery config.

How it works?

  • Introduced a LocalizationConfigUpdater component that wraps the useLocalizationConfig hook
  • The component is conditionally rendered only when storeConfig.localization?.enabled is true
  • Uses the component wrapper pattern to follow React's Rules of Hooks, avoiding conditional hook calls

When localization.enabled is false, the component is not mounted and the hook is not executed.

How to test it?

  • With localization.enabled: true in discovery.config, confirm the session is updated based on the binding/region
  • With localization.enabled: false in discovery.config, confirm the app starts without errors and no localization logic is initialized

Starters Deploy Preview

N/A

References

Summary by CodeRabbit

  • Refactor
    • Localization initialization now runs only when the localization feature is enabled, ensuring localization setup is performed conditionally.

@lemagnetic
lemagnetic requested a review from a team as a code owner February 19, 2026 23:40
@lemagnetic
lemagnetic requested review from gabpaladino and renatamottam and removed request for a team February 19, 2026 23:40
@coderabbitai

coderabbitai Bot commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉


Walkthrough

Introduces a new internal component, LocalizationConfigUpdater, which calls useLocalizationConfig() and is rendered conditionally from App when storeConfig.localization?.enabled is true, moving localization initialization from immediate hook invocation to conditional render-time execution.

Changes

Cohort / File(s) Summary
Localization Config Initialization
packages/core/src/pages/_app.tsx
Extracted useLocalizationConfig into a new internal LocalizationConfigUpdater component; replaced direct hook call in App with conditional render guarded by storeConfig.localization?.enabled, changing control flow from immediate effect to render-side updater.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant App as App
    participant Store as storeConfig
    participant Updater as LocalizationConfigUpdater
    participant Hook as useLocalizationConfig

    App->>Store: read storeConfig.localization?.enabled
    alt enabled == true
        App->>Updater: render LocalizationConfigUpdater
        Updater->>Hook: call useLocalizationConfig()
        Hook->>Hook: initialize localization config
    else enabled == false
        App->>App: skip rendering Updater
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

🌍 A tiny guard now checks the gate,
Hooks wait to run until the flag says "wait".
From App to Updater the call is steered,
Localization wakes only when it's cleared ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: conditionally initializing useLocalizationConfig only when localization is enabled, which is the core objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/conditional-localization-config

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

@codesandbox-ci

codesandbox-ci Bot commented Feb 19, 2026 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/core/src/pages/_app.tsx (1)

34-34: Pre-existing conditional hook call — apply the same fix introduced here.

storeConfig.experimental?.scrollRestoration && useScrollRestoration() has the same Rules of Hooks violation this PR is resolving for useLocalizationConfig. Since storeConfig is a static config the hook count never changes in practice, but it will still fire linting errors and could break under future refactors. Apply the same wrapper pattern for consistency:

♻️ Suggested fix — ScrollRestorationUpdater wrapper
+function ScrollRestorationUpdater() {
+  useScrollRestoration()
+  return null
+}
+
 function App({ Component, pageProps }: AppProps) {
   useGeolocation()
-  storeConfig.experimental?.scrollRestoration && useScrollRestoration()
   ...
   return (
     <ErrorBoundary>
       {storeConfig.localization?.enabled && <LocalizationConfigUpdater />}
+      {storeConfig.experimental?.scrollRestoration && <ScrollRestorationUpdater />}
       ...
     </ErrorBoundary>
   )
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/pages/_app.tsx` at line 34, The conditional hook call
storeConfig.experimental?.scrollRestoration && useScrollRestoration() violates
the Rules of Hooks; create a small wrapper component (e.g.,
ScrollRestorationUpdater) that always renders but internally calls
useScrollRestoration() when storeConfig.experimental?.scrollRestoration is
truthy, then include <ScrollRestorationUpdater /> in the App tree instead of the
inline conditional; reference storeConfig and useScrollRestoration inside that
component so the hook call is unconditional within a component and lint errors
are resolved.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/core/src/pages/_app.tsx`:
- Line 34: The conditional hook call storeConfig.experimental?.scrollRestoration
&& useScrollRestoration() violates the Rules of Hooks; create a small wrapper
component (e.g., ScrollRestorationUpdater) that always renders but internally
calls useScrollRestoration() when storeConfig.experimental?.scrollRestoration is
truthy, then include <ScrollRestorationUpdater /> in the App tree instead of the
inline conditional; reference storeConfig and useScrollRestoration inside that
component so the hook call is unconditional within a component and lint errors
are resolved.

@lemagnetic
lemagnetic force-pushed the feat/conditional-localization-config branch from 24b505c to 4023caa Compare February 20, 2026 22:16
@lemagnetic
lemagnetic merged commit 5da1a3c into feat/multilanguage Feb 23, 2026
3 checks passed
@lemagnetic
lemagnetic deleted the feat/conditional-localization-config branch February 23, 2026 17:04
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