-
Notifications
You must be signed in to change notification settings - Fork 20
Chore/tavanogui #1484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Chore/tavanogui #1484
Conversation
WalkthroughThe PR modifies VTEX cart and cookie handling to propagate a shouldClearCartCookie decision through the request/response pipeline. When a mismatched cart is detected in the loader, this flag is returned and used to conditionally clear the checkout cookie via proxySetCookie. Checkout-related proxy routes now include Vary headers for caching. Changes
Sequence DiagramsequenceDiagram
participant Loader as Loader
participant LogMismatch as logMismatchedCart
participant Cookie as proxySetCookie
participant Response as Response
Loader->>LogMismatch: Check cart mismatch
alt Cart mismatch detected
LogMismatch->>LogMismatch: Log mismatch
LogMismatch-->>Loader: { shouldClearCartCookie: true }
else No mismatch
LogMismatch-->>Loader: { shouldClearCartCookie: false }
end
Loader->>Cookie: proxySetCookie(..., { shouldClearCartCookie })
alt shouldClearCartCookie && cookie is checkout.vtex.com
Cookie->>Response: Set cookie with empty value<br/>(expires/maxAge = 0)
else
Cookie->>Response: Set cookie normally
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. 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 |
Tagging OptionsShould a new tag be published when this PR is merged?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
vtex/utils/cookies.ts (1)
12-40: Tighten cookie‑clearing attributes (domain/path reuse) for reliabilityThe
shouldClearCartCookieflow looks correct and the signature change is backward compatible, but the clear branch can be a bit safer:
- When
toDomainis not provided,domainis forced to"", instead of reusingcookie.domainor omittingdomainentirely.pathis hard‑coded to"/", which assumes the originalcheckout.vtex.comcookie always uses that path. If VTEX ever ships it with a different path, this clear may not take effect.You can reuse the derived
newCookieas a base to avoid drifting from the original attributes:- if(cookie.name === "checkout.vtex.com" && options?.shouldClearCartCookie) { - - setCookie(to, { - name: "checkout.vtex.com", - value: "", - expires: new Date(0), - maxAge: 0, - path: "/", - secure: true, - httpOnly: true, - domain: newDomain ? newDomain?.hostname : "", - }); - } else { - setCookie(to, newCookie); - } + if (cookie.name === "checkout.vtex.com" && options?.shouldClearCartCookie) { + setCookie(to, { + ...newCookie, + value: "", + expires: new Date(0), + maxAge: 0, + }); + } else { + setCookie(to, newCookie); + }This keeps domain/path/flags aligned with whatever VTEX sends while still clearing the cookie.
🧹 Nitpick comments (1)
vtex/loaders/cart.ts (1)
109-115: Update comment to reflect side‑effect (not just “temporary logging”)
logMismatchedCartis now used to decide whether to clear the cart cookie, not just for “temporary logging”:// Temporary logging to check for cart mismatch const { shouldClearCartCookie } = logMismatchedCart(cart, req, ctx); proxySetCookie(..., { shouldClearCartCookie });Consider updating the comment (or removing it) to avoid misleading future readers into thinking this is non‑behavioral telemetry.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
vtex/loaders/cart.ts(3 hunks)vtex/loaders/proxy.ts(1 hunks)vtex/utils/cookies.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
vtex/loaders/cart.ts (1)
vtex/utils/cookies.ts (1)
proxySetCookie(8-42)
🔇 Additional comments (2)
vtex/loaders/cart.ts (1)
28-74: Semantics of whenshouldClearCartCookieis true look coherentThe refactor of
logMismatchedCartto always return{ shouldClearCartCookie: boolean }is clean, and limitingtrueto the explicit email‑mismatch case makes the behavior predictable. Early exits on missing auth cookie or JWT parse errors returningfalseare reasonable defaults.If product requirements ever change (e.g., “any suspicious auth cookie issue should trigger a cart reset”), you now have a single place to adjust that policy, which is nice. No functional issues spotted here.
vtex/loaders/proxy.ts (1)
80-85: Handler confirms Vary header will overwrite, not merge—but no conflict in this changeVerification confirms your concern: the proxy handler applies
customHeadersviaheaders.set(key, value)(line 146 in website/handlers/proxy.ts), which overwrites instead of merging. Only thecookieheader has special append logic (line 141).However, this doesn't create a practical issue here:
- The headers object is freshly initialized from incoming request headers, which typically don't include
Vary(it's a response header).- No other code in vtex/loaders/proxy.ts sets
customHeaderswith a conflictingVaryheader.- The added
Vary: Cookie, Accept-Encodingfor/checkoutpaths is applied cleanly without overwriting anything.The architectural point stands (handler could benefit from
Varyheader merging like it does for cookies), but this specific change is safe to proceed with.
What is this Contribution About?
Please provide a brief description of the changes or enhancements you are proposing in this pull request.
Issue Link
Please link to the relevant issue that this pull request addresses:
Loom Video
Demonstration Link
Summary by CodeRabbit
Release Notes
Bug Fixes
Performance
✏️ Tip: You can customize this high-level summary in your review settings.