Repository navigation
fix(astro): Insert Clerk's tags once before the closing head tag (Core 2) - #10901
Conversation
…e 2) Backport the head tag changes and the $billingStore load gate from main. clerkMiddleware now scans the streamed HTML with createHeadInjector, which tracks tokenizer state across chunks and inserts once before </head>, or before <body> when </head> is missing. The SSR auth state and client env go in base64url <meta> tags, and clerk-js is preloaded with a <link> tag. The integration's page script adds the clerk-js script, so getClientSafeEnv now also passes the publishable key and the clerk-js URL, variant, and version. $billingStore now emits only after clerk.load() resolves. Adds vitest to @clerk/astro on this branch so the new tests run in CI.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 6a0d6c8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
|



Description
Backports two
@clerk/astrofixes frommainto Core 2.Head tags.
clerkMiddlewareused to look for the bytes</head>in each streamed chunk and insert Clerk's tags before every match. It missed a</head>that was split across two chunks, and it could insert at a</head>that wasn't the document's real closing tag. It now usescreateHeadInjector, which tracks the HTML tokenizer state across chunks and inserts once before the real</head>, or before<body>when the page has no</head>.The inserted markup changes too:
The integration's page script reads both
<meta>tags and adds the clerk-js<script>. The browser reuses the preloaded response. The server used to decide the clerk-js URL, sogetClientSafeEnvnow also passes the publishable key andPUBLIC_CLERK_JS_URL,PUBLIC_CLERK_JS_VARIANT, andPUBLIC_CLERK_JS_VERSION. Env vars set only at runtime, like Cloudflarelocals.runtime.env, still reach the client.$billingStore. The store now emitsclerk.billingonly afterclerk.load()resolves. Before, a subscriber could callgetPlans()before the dev browser was set up and getdev_browser_unauthenticatedon development instances. Same fix as #10894.@clerk/astrohad no unit tests on this branch, so this addsvitest.config.ts,vitest.setup.ts, and atestscript, matchingmain.How to test
pnpm --filter @clerk/astro test@astrojs/node. Clerk 5.128.2 loaded from the preloaded URL,Clerk.loadedwastrue, and the FAPI requests carried the dev browser JWT.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
🤖 Generated with Claude under Rob's supervision.