Skip to content

Fixed: dropped the prevOrderKeyRef/cartKey short-circuit so the layou…#147

Merged
damianlegawiec merged 2 commits into
mainfrom
fix/checkout-sidebar-caching
May 12, 2026
Merged

Fixed: dropped the prevOrderKeyRef/cartKey short-circuit so the layou…#147
damianlegawiec merged 2 commits into
mainfrom
fix/checkout-sidebar-caching

Conversation

@damianlegawiec
Copy link
Copy Markdown
Member

@damianlegawiec damianlegawiec commented May 12, 2026

…t effect always re-publishes the sidebar when cart changes

This fixes an issue with stale checkout sidebar

Summary by CodeRabbit

  • Refactor
    • Optimized checkout page sidebar rendering and cart state synchronization logic.
    • Updated checkout analytics initialization to ensure consistent event tracking and fresh cart data reconciliation on page load.

Review Change Stack

…t effect always re-publishes the sidebar when cart changes

This fixes an issue with stale checkout sidebar
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
storefront Ready Ready Preview, Comment May 12, 2026 0:44am

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Warning

Rate limit exceeded

@damianlegawiec has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes and 25 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 40e8d0f5-ae0f-4731-a560-b037d48df0f6

📥 Commits

Reviewing files that changed from the base of the PR and between f87dd51 and ffd23db.

📒 Files selected for processing (1)
  • src/app/[country]/[locale]/(checkout)/checkout/[id]/CheckoutPageContent.tsx

Walkthrough

The checkout page component refactors its cart state management lifecycle. The mount effect now unifies cart reconciliation and analytics firing, fetching fresh data regardless of SSR initialData availability. The sidebar layout effect simplifies to always republish state when cart changes, removing the previous cartKey optimization.

Changes

Checkout page cart lifecycle and sidebar updates

Layer / File(s) Summary
Mount-time cart reconciliation and analytics
src/app/[country]/[locale]/(checkout)/checkout/[id]/CheckoutPageContent.tsx
The mount useEffect fires begin_checkout once via a ref guard, fetches fresh cart data for reconciliation even when initialData exists (preserving the SSR sidebar until refresh), and falls back to loadOrder() when initialData is absent.
Sidebar state publishing on cart changes
src/app/[country]/[locale]/(checkout)/checkout/[id]/CheckoutPageContent.tsx
The useLayoutEffect for sidebar updates removes the cartKey-based change detection; it now always re-publishes sidebar state when cart changes, with simplified comments and updated dependency list.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 When carts refresh, the sidebar sings,
No keys to track, just cart state swings.
Mount once, guard the analytics flame,
Then publish fresh—the flow's the same.
Simpler paths make clearer lanes! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly matches the main change described in the PR objectives: removing the prevOrderKeyRef/cartKey short-circuit to fix stale checkout sidebar caching.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/checkout-sidebar-caching

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.

Copy link
Copy Markdown

@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

🤖 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 `@src/app/`[country]/[locale]/(checkout)/checkout/[id]/CheckoutPageContent.tsx:
- Around line 246-252: The refresh path using getCheckoutOrder only calls
setCart and therefore skips the completion redirect and not-found handling
implemented in loadOrder; update the refresh logic in CheckoutPageContent so
that after getCheckoutOrder resolves you either call loadOrder() (reusing its
redirect/not-found/completed-order handling) or copy its handling: if freshCart
is falsy or indicates a completed/missing order run the same redirect/not-found
flows instead of just setCart, and propagate errors to the existing catch path
so users aren’t left on a stale/invalid checkout page.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 27bd4763-f46a-4cf2-b908-3c16d9c67edb

📥 Commits

Reviewing files that changed from the base of the PR and between 4123e9e and f87dd51.

📒 Files selected for processing (1)
  • src/app/[country]/[locale]/(checkout)/checkout/[id]/CheckoutPageContent.tsx

Comment thread src/app/[country]/[locale]/(checkout)/checkout/[id]/CheckoutPageContent.tsx Outdated
@damianlegawiec damianlegawiec merged commit abde12d into main May 12, 2026
6 checks passed
damianlegawiec added a commit that referenced this pull request May 14, 2026
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.

1 participant