Skip to content

Fix geo country cookie TypeError#706

Merged
Wituareard merged 2 commits intoPauseAI:mainfrom
RisingOrange:fix/geo-country-cookie
Mar 26, 2026
Merged

Fix geo country cookie TypeError#706
Wituareard merged 2 commits intoPauseAI:mainfrom
RisingOrange:fix/geo-country-cookie

Conversation

@RisingOrange
Copy link
Copy Markdown
Contributor

@RisingOrange RisingOrange commented Mar 26, 2026

geo.country from Netlify's edge function context is an object { code?: string; name?: string }, not a string. This caused two bugs introduced in #695:

  • TypeError in production: Passing the object as SetCookie's value caused quote() to call .includes() on an object → TypeError: t.includes is not a function
  • Cookie reset on every page load: Comparing the object to the string cookie value always evaluated to true, so the cookie was re-set and selectBanners() was called on every page visit

Fix

Use geo.country.code (the string country code) instead of geo.country in both the comparison and the cookie value.

Test plan

The geo API returns 501 in dev (no Netlify platform), so these can only be verified on a deploy preview:

  • No TypeError: t.includes is not a function in the console
  • The geo_country cookie is set to a country code string (e.g. "US"), not [object Object]

geo.country is a Netlify Geo object {code, name}, not a string.
Using it directly as SetCookie value caused TypeError in production,
and the object-to-string comparison always evaluated to true,
resetting the cookie on every page load.
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 26, 2026

👷 Deploy request for pauseai pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c946f6f

@RisingOrange RisingOrange changed the title Fix geo country cookie TypeError in production Fix geo country cookie TypeError Mar 26, 2026
@Wituareard
Copy link
Copy Markdown
Collaborator

Thanks

@Wituareard Wituareard merged commit 414b5c4 into PauseAI:main Mar 26, 2026
1 check passed
@Wituareard
Copy link
Copy Markdown
Collaborator

Thinking about whether we should check for [object Object] or maybe broader "invalid country code" for the people who visited in the meantime

@RisingOrange
Copy link
Copy Markdown
Contributor Author

RisingOrange commented Mar 26, 2026

Should be fine as-is. The cookie gets overwritten on the next visit when the value doesn't match:

if (geo?.country?.code && geo.country.code !== geoCountryCookie) {
document.cookie = new SetCookie({
name: 'geo_country',
value: geo.country.code,
path: '/',
maxAge: 31536000,
sameSite: 'Lax'
}).toString() // 1 year
window.selectBanners()

@RisingOrange RisingOrange deleted the fix/geo-country-cookie branch March 26, 2026 23:40
@Wituareard
Copy link
Copy Markdown
Collaborator

Oh right, thanks for the clarification

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