Skip to content

apps-vtex/tanstack: vtex_session/vtex_segment duplicated (host-only + Domain) — server path drops Domain, dedup ignores it #643

Open

Description

@aline-pereira

What happens

On a TanStack storefront the browser ends up holding two vtex_session and two vtex_segment cookies:

  • Through the /api/* proxy, VTEX Set-Cookie is rewritten to Domain=<host> (utils/proxy.ts → rewriteSetCookieDomain). That matches Fresh's proxySetCookie.
  • On the server path, vtexFetchWithCookies (SSR, /deco/invoke) forwards the cookie host-only. rewriteCookieDomain in client.ts only replaces an existing Domain= attribute, and VTEX sends none.

The browser treats a host-only cookie and a Domain=<host> cookie as different cookies, so both are sent on every request. SSR and VTEX then each read a different copy.

Impact we measured (oficina-tanstack, Prime account): the SSR rendered Prime prices, but /api/segments answered priceTables: null (production: oficinaprime).

Second issue

deduplicateSetCookies in @decocms/tanstack/src/sdk/workerEntry.ts keys on the cookie name only. So a response can't expire the host-only copy and write the Domain one at the same time: one of the two lines is dropped.

Repro

# raw VTEX: no Domain
curl -sD- -o/dev/null -X PATCH https://<account>.vtexcommercestable.com.br/api/sessions -d '{"public":{}}' | grep -i set-cookie
# proxy: Domain=<host>; server-side invoke/SSR: no Domain → two cookies in the jar

Suggested fix

  • rewriteCookieDomain: when host is known, add Domain=<host> if the attribute is absent, like proxySetCookie.
  • deduplicateSetCookies: key on name + Domain + Path.

Site-side workaround: deco-sites/oficina-tanstack#478 (src/setup/commerce-init.ts).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions