Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ready-cats-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/astro': patch
---

Fixed an issue when using `ClientRouter` where Clerk components don't load until navigation is performed.
7 changes: 5 additions & 2 deletions packages/astro/src/integration/create-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ function createIntegration<Params extends HotloadAstroClerkIntegrationParams>()
}

if (transitionEnabledOnThisPage()) {
const { navigate, swapFunctions } = await import('astro:transitions/client');
// We must do the dynamic imports within the event listeners because otherwise we may race and miss initial astro:page-load
document.addEventListener('astro:before-swap', async (e) => {
const { swapFunctions } = await import('astro:transitions/client');

document.addEventListener('astro:before-swap', (e) => {
const clerkComponents = document.querySelector('#clerk-components');
// Keep the div element added by Clerk
if (clerkComponents) {
Expand All @@ -139,6 +140,8 @@ function createIntegration<Params extends HotloadAstroClerkIntegrationParams>()
});

document.addEventListener('astro:page-load', async (e) => {
const { navigate } = await import('astro:transitions/client');

await runInjectionScript({
...${JSON.stringify(internalParams)},
routerPush: navigate,
Expand Down