File tree Expand file tree Collapse file tree
packages/astro/src/integration Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' @clerk/astro ' : patch
3+ ---
4+
5+ Fixed an issue when using ` ClientRouter ` where Clerk components don't load until navigation is performed.
Original file line number Diff line number Diff line change @@ -126,9 +126,10 @@ function createIntegration<Params extends HotloadAstroClerkIntegrationParams>()
126126 }
127127
128128 if (transitionEnabledOnThisPage()) {
129- const { navigate, swapFunctions } = await import('astro:transitions/client');
129+ // We must do the dynamic imports within the event listeners because otherwise we may race and miss initial astro:page-load
130+ document.addEventListener('astro:before-swap', async (e) => {
131+ const { swapFunctions } = await import('astro:transitions/client');
130132
131- document.addEventListener('astro:before-swap', (e) => {
132133 const clerkComponents = document.querySelector('#clerk-components');
133134 // Keep the div element added by Clerk
134135 if (clerkComponents) {
@@ -140,6 +141,8 @@ function createIntegration<Params extends HotloadAstroClerkIntegrationParams>()
140141 });
141142
142143 document.addEventListener('astro:page-load', async (e) => {
144+ const { navigate } = await import('astro:transitions/client');
145+
143146 await runInjectionScript({
144147 ...${ JSON . stringify ( internalParams ) } ,
145148 routerPush: navigate,
You can’t perform that action at this time.
0 commit comments