Repository navigation
feat(core): init useLocalizationConfig only when localization.enabled is true - #3216
Conversation
|
No actionable comments were generated in the recent review. 🎉 WalkthroughIntroduces a new internal component, Changes
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
|
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. |
There was a problem hiding this comment.
🧹 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 foruseLocalizationConfig. SincestoreConfigis 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.
24b505c to
4023caa
Compare
What's the purpose of this pull request?
Stores with localization disabled (
localization.enabled: false) in discovery config were still initializing theuseLocalizationConfighook, which accessesconfig.localization.localesand 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?
LocalizationConfigUpdatercomponent that wraps theuseLocalizationConfighookstoreConfig.localization?.enabledistrueWhen
localization.enabledisfalse, the component is not mounted and the hook is not executed.How to test it?
localization.enabled: trueindiscovery.config, confirm the session is updated based on the binding/regionlocalization.enabled: falseindiscovery.config, confirm the app starts without errors and no localization logic is initializedStarters Deploy Preview
N/A
References
Summary by CodeRabbit