Repository navigation
chore: improve session validation logic by conditionally checking localization flag - #3296
Conversation
…localization settings
WalkthroughThe ChangesSession Localization Conditional Guard
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. |
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/diagnostics
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/sdk/session/index.ts`:
- Around line 145-147: The JSON.parse on session.channel when building newChanel
can throw on malformed persisted data; modify the code around newChanel (the
JSON.stringify call that spreads JSON.parse(session.channel ?? '{}')) to safely
parse session.channel (e.g., use a try/catch or a safeParse helper that returns
{} on error) before constructing newChanel so parsing errors do not occur
outside the existing validation try block (refer to newChanel and
session.channel in this file and ensure the safe parse happens prior to creating
newChanel or move it inside the surrounding try that calls validateSession).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 12d8dd13-a517-485d-a4e1-c7a3c301604d
📒 Files selected for processing (1)
packages/core/src/sdk/session/index.ts
| const newChanel = JSON.stringify({ | ||
| ...(JSON.parse(session.channel ?? '{}') ?? {}), | ||
| salesChannel: settings.salesChannel, |
There was a problem hiding this comment.
Guard session.channel parsing to avoid pre-validation crashes
At Line 146, JSON.parse(session.channel ?? '{}') can throw for malformed persisted data, and this happens before the try block (Line 179). That can break validateSession entirely when localization is enabled.
Suggested fix
if (storeConfig.localization?.enabled) {
const settings = getSettings()
- const newChanel = JSON.stringify({
- ...(JSON.parse(session.channel ?? '{}') ?? {}),
+ let parsedChannel: Record<string, unknown> = {}
+ try {
+ parsedChannel = JSON.parse(session.channel ?? '{}') ?? {}
+ } catch {
+ parsedChannel = {}
+ }
+
+ const newChanel = JSON.stringify({
+ ...parsedChannel,
salesChannel: settings.salesChannel,
})🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/core/src/sdk/session/index.ts` around lines 145 - 147, The
JSON.parse on session.channel when building newChanel can throw on malformed
persisted data; modify the code around newChanel (the JSON.stringify call that
spreads JSON.parse(session.channel ?? '{}')) to safely parse session.channel
(e.g., use a try/catch or a safeParse helper that returns {} on error) before
constructing newChanel so parsing errors do not occur outside the existing
validation try block (refer to newChanel and session.channel in this file and
ensure the safe parse happens prior to creating newChanel or move it inside the
surrounding try that calls validateSession).
What's the purpose of this pull request?
This pull request introduces a conditional check for localization settings in the
validateSessionfunction to ensure that localization-related session updates only occur when localization is enabled. This helps prevent unnecessary or incorrect modifications to session data when localization is not in use.Session validation improvements:
storeConfig.localization?.enabledbefore updating session currency and channel based on localization settings invalidateSessioninsession/index.ts. [1] [2]Summary by CodeRabbit