Skip to content

fix(clerk-js,astro,nuxt,tanstack-react-start,remix,react-router): Introduce helper function to prevent infinite handshake in Netlify #5656

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Apr 17, 2025

Description

This PR is a follow-up to #4745 but applies the changes to all SDKs (except @clerk/nextjs).

This fixes a handshake redirect loop issue in apps deployed to Netlify with Clerk development instance (see #5547). I opened a thread on Netlify's side about this with full info, which can be seen here. Multiple solutions have been tried, including the Netlify-Vary header with no success.

I also thought of moving the handleNetlifyCacheInDevInstance function to @clerk/backend but this may introduce unnecessary complexity. The goal of this PR is to temporarily fix the issue until we find a better solution but open for discussions!

You can test it with the ff. apps deployed to Netlify using this PRs snapshots + Clerk dev instance (you should not experience a redirect loop when visiting any of them):

Resolves ECO-603

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Apr 17, 2025

🦋 Changeset detected

Latest commit: 0cfc484

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

This PR includes changesets to release 19 packages
Name Type
@clerk/astro Patch
@clerk/clerk-js Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/shared Patch
@clerk/tanstack-react-start Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/agent-toolkit Patch
@clerk/backend Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/clerk-react Patch
@clerk/testing Patch
@clerk/vue 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

Copy link

vercel bot commented Apr 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 23, 2025 6:13pm

@clerk clerk deleted a comment from clerk-cookie Apr 17, 2025
@wobsoriano
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @wobsoriano - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.0.24-snapshot.v20250417032557
@clerk/astro 2.6.6-snapshot.v20250417032557
@clerk/backend 1.29.1-snapshot.v20250417032557
@clerk/chrome-extension 2.2.31-snapshot.v20250417032557
@clerk/clerk-js 5.61.2-snapshot.v20250417032557
@clerk/elements 0.23.16-snapshot.v20250417032557
@clerk/clerk-expo 2.9.14-snapshot.v20250417032557
@clerk/expo-passkeys 0.2.8-snapshot.v20250417032557
@clerk/express 1.4.7-snapshot.v20250417032557
@clerk/fastify 2.2.7-snapshot.v20250417032557
@clerk/localizations 3.13.12-snapshot.v20250417032557
@clerk/nextjs 6.16.0-snapshot.v20250417032557
@clerk/nuxt 1.5.7-snapshot.v20250417032557
@clerk/clerk-react 5.28.2-snapshot.v20250417032557
@clerk/react-router 1.2.7-snapshot.v20250417032557
@clerk/remix 4.5.19-snapshot.v20250417032557
@clerk/shared 3.7.2-snapshot.v20250417032557
@clerk/tanstack-react-start 0.13.7-snapshot.v20250417032557
@clerk/testing 1.4.41-snapshot.v20250417032557
@clerk/themes 2.2.34-snapshot.v20250417032557
@clerk/types 4.54.2-snapshot.v20250417032557
@clerk/vue 1.6.3-snapshot.v20250417032557

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/[email protected] --save-exact

@clerk/astro

npm i @clerk/[email protected] --save-exact

@clerk/backend

npm i @clerk/[email protected] --save-exact

@clerk/chrome-extension

npm i @clerk/[email protected] --save-exact

@clerk/clerk-js

npm i @clerk/[email protected] --save-exact

@clerk/elements

npm i @clerk/[email protected] --save-exact

@clerk/clerk-expo

npm i @clerk/[email protected] --save-exact

@clerk/expo-passkeys

npm i @clerk/[email protected] --save-exact

@clerk/express

npm i @clerk/[email protected] --save-exact

@clerk/fastify

npm i @clerk/[email protected] --save-exact

@clerk/localizations

npm i @clerk/[email protected] --save-exact

@clerk/nextjs

npm i @clerk/[email protected] --save-exact

@clerk/nuxt

npm i @clerk/[email protected] --save-exact

@clerk/clerk-react

npm i @clerk/[email protected] --save-exact

@clerk/react-router

npm i @clerk/[email protected] --save-exact

@clerk/remix

npm i @clerk/[email protected] --save-exact

@clerk/shared

npm i @clerk/[email protected] --save-exact

@clerk/tanstack-react-start

npm i @clerk/[email protected] --save-exact

@clerk/testing

npm i @clerk/[email protected] --save-exact

@clerk/themes

npm i @clerk/[email protected] --save-exact

@clerk/types

npm i @clerk/[email protected] --save-exact

@clerk/vue

npm i @clerk/[email protected] --save-exact

publishableKey: string;
}) {
// eslint-disable-next-line turbo/no-undeclared-env-vars
const isOnNetlify = process.env.URL?.endsWith('netlify.app') || Boolean(process.env.NETLIFY_FUNCTIONS_TOKEN);
Copy link
Member Author

@wobsoriano wobsoriano Apr 17, 2025

Choose a reason for hiding this comment

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

URL and NETLIFY_FUNCTIONS_TOKEN are runtime environment variables injected by Netlify. We can use this to determine if this patch should run.

Copy link
Member

Choose a reason for hiding this comment

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

Can't we use process.env.NETLIFY?

URL will not always end with netlify.app since it can also be your custom domain, as per https://docs.netlify.com/functions/environment-variables/#functions

Copy link
Member Author

Choose a reason for hiding this comment

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

It's for build time only and not available in other SDKs at runtime (but worked in Astro 🤔 ). I added it just now as fallback!

@wobsoriano wobsoriano requested a review from LekoArts April 17, 2025 04:01
@wobsoriano wobsoriano requested a review from brkalow April 17, 2025 04:01
@wobsoriano wobsoriano marked this pull request as ready for review April 17, 2025 04:01
publishableKey: string;
}) {
// eslint-disable-next-line turbo/no-undeclared-env-vars
const isOnNetlify = process.env.URL?.endsWith('netlify.app') || Boolean(process.env.NETLIFY_FUNCTIONS_TOKEN);
Copy link
Member

Choose a reason for hiding this comment

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

Can't we use process.env.NETLIFY?

URL will not always end with netlify.app since it can also be your custom domain, as per https://docs.netlify.com/functions/environment-variables/#functions

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

Successfully merging this pull request may close these issues.

3 participants