Skip to content

feat(core): add locale parameter to client.fetch()#2977

Open
jorgemoya wants to merge 1 commit intocanaryfrom
LTRAC-226/locale-param
Open

feat(core): add locale parameter to client.fetch()#2977
jorgemoya wants to merge 1 commit intocanaryfrom
LTRAC-226/locale-param

Conversation

@jorgemoya
Copy link
Copy Markdown
Contributor

@jorgemoya jorgemoya commented Apr 13, 2026

Linear: LTRAC-226

What/Why?

Prerequisite for guest query caching with unstable_cache.

  • Adds an optional locale parameter to client.fetch() for use in cached contexts where getLocale() is unavailable
  • Wraps the headers() call in beforeRequest with try/catch so it gracefully degrades inside unstable_cache

No changes to getChannelId or beforeRequest callback signatures.

Second in a series of PRs splitting #2910 into smaller pieces. Depends on #2976.

Rollout/Rollback

Backwards compatible — locale is optional and all existing call sites continue to work unchanged. Rollback is a simple revert.

Testing

  • pnpm build passes
  • pnpm lint passes
  • Verify multi-locale storefronts still resolve the correct channel ID
  • Verify IP forwarding headers still appear on uncached requests

🤖 Generated with Claude Code

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 13, 2026

🦋 Changeset detected

Latest commit: 21067ed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@bigcommerce/catalyst-client Patch
@bigcommerce/catalyst-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 13, 2026

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

Project Deployment Actions Updated (UTC)
catalyst Ready Ready Preview, Comment Apr 14, 2026 2:23pm

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Bundle Size Report

Comparing against baseline from a8dd99e (2026-04-14).

No bundle size changes detected.

@jorgemoya jorgemoya changed the title LTRAC-226: Add locale parameter to client.fetch() and harden beforeRequest LTRAC-226: feat(core): add locale parameter to client.fetch() and harden beforeRequest Apr 13, 2026
@jorgemoya jorgemoya changed the title LTRAC-226: feat(core): add locale parameter to client.fetch() and harden beforeRequest feat(core): add locale parameter to client.fetch() and harden beforeRequest Apr 13, 2026
@jorgemoya jorgemoya marked this pull request as ready for review April 13, 2026 19:48
@jorgemoya jorgemoya requested a review from a team as a code owner April 13, 2026 19:48
@github-actions
Copy link
Copy Markdown
Contributor

Unlighthouse Performance Comparison — Vercel

Comparing PR preview deployment Unlighthouse scores vs production Unlighthouse scores.

Summary Score

Aggregate score across all categories as reported by Unlighthouse.

Prod Desktop Prod Mobile Preview Desktop Preview Mobile
Score 92 94 91 94

Category Scores

Category Prod Desktop Prod Mobile Preview Desktop Preview Mobile
Performance 77 95 76 91
Accessibility 95 95 95 98
Best Practices 100 100 95 100
SEO 88 100 100 100

Core Web Vitals

Metric Prod Desktop Prod Mobile Preview Desktop Preview Mobile
LCP 3.5 s 2.9 s 3.8 s 3.5 s
CLS 0.036 0 0.037 0
FCP 1.1 s 1.2 s 1.2 s 1.2 s
TBT 0 ms 0 ms 10 ms 0 ms
Max Potential FID 50 ms 50 ms 60 ms 40 ms
Time to Interactive 3.5 s 3.5 s 3.8 s 3.5 s

Full Unlighthouse report →

requestHeaders['Accept-Language'] = locale;
// Use explicit locale when available (required inside unstable_cache where
// getLocale() would fail), fall back to next-intl for normal requests.
const resolvedLocale = locale ?? (await getLocale());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing in the resolved locale, could we do the same as above where we try/catch instead? Mostly asking here cause I am not sure we want to modify the client and I am trying to think of a way where we don't have to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, why not modify the client?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just don't want to make a change that we don't have to. I would also say changing the client deserves it's own PR.

Copy link
Copy Markdown
Contributor Author

@jorgemoya jorgemoya Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I played with this for a bit. Honestly, if we can't modify getChannelId or beforeRequest, what is the point of this PR? Keep in mind the interface adds an optional prop (a patch change imo).

Passing locale is the only way to have this available in unstable_cache and (eventually) use cache . It will be required for use cache. Since we will be passing locale to all queries within these cache contexts, I think it makes sense that we phase out getLocale entirely.

In fact, I would make locale mandatory, not optional. I have a PR for it already 😆 .

…equest

Add optional locale parameter to client.fetch() for use in cached
contexts. Wrap headers() call in beforeRequest with try/catch so it
gracefully degrades inside unstable_cache.

No changes to getChannelId or beforeRequest callback signatures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jorgemoya jorgemoya force-pushed the LTRAC-226/locale-param branch from d54fbd1 to 21067ed Compare April 14, 2026 14:22
@jorgemoya jorgemoya changed the title feat(core): add locale parameter to client.fetch() and harden beforeRequest feat(core): add locale parameter to client.fetch() Apr 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.

2 participants