-
Notifications
You must be signed in to change notification settings - Fork 294
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
feat(astro,clerk-js): View transitions support #4342
Changes from all commits
203b721
d121fb0
c3afcbb
286a9ee
9cd9d12
812a6b8
78908b6
09cb9bd
726f7c3
3928246
18c28d4
ce98122
d37a5e7
7915b29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@clerk/astro": minor | ||
"@clerk/clerk-js": patch | ||
--- | ||
|
||
Add support for Astro View Transitions |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1526,6 +1526,17 @@ export class Clerk implements ClerkInterface { | |
return this.navigate(to); | ||
} | ||
|
||
/** | ||
* This clears the emotion cache, which is particularly useful | ||
* when working with Astro View Transitions to prevent style loss during page navigation. | ||
* | ||
* For more info on the issue, see: | ||
* https://github.com/withastro/astro/issues/11000 | ||
*/ | ||
__internal_flushEmotionCache() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nikosdouvlis asking in advance here if there's a better way to access the internal emotion cache rather than what I did here. Any advice would do! Issue: With Astro's View Transitions, navigating to a new page removes unnecessary head elements, including the emotion cache. Clearing the cache resolves this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, this adds 140KB to the bundle size so this is not a good solution |
||
return this.#componentControls?.ensureMounted().then(controls => controls.flushEmotionCache()); | ||
} | ||
|
||
#hasJustSynced = () => getClerkQueryParam(CLERK_SYNCED) === 'true'; | ||
#clearJustSynced = () => removeClerkQueryParam(CLERK_SYNCED); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ import { | |
LazyProviders, | ||
OrganizationSwitcherPrefetch, | ||
} from './lazyModules/providers'; | ||
import { emotionCache } from './styledSystem/InternalThemeProvider'; | ||
import type { AvailableComponentProps } from './types'; | ||
|
||
const ROOT_ELEMENT_ID = 'clerk-components'; | ||
|
@@ -90,6 +91,7 @@ export type ComponentControls = { | |
}, | ||
) => void; | ||
prefetch: (component: 'organizationSwitcher') => void; | ||
flushEmotionCache: () => void; | ||
// Special case, as the impersonation fab mounts automatically | ||
mountImpersonationFab: () => void; | ||
}; | ||
|
@@ -309,6 +311,12 @@ const Components = (props: ComponentsProps) => { | |
setState(s => ({ ...s, [`${component}Prefetch`]: true })); | ||
}; | ||
|
||
componentsControls.flushEmotionCache = () => { | ||
emotionCache.sheet.flush(); | ||
emotionCache.inserted = {}; | ||
emotionCache.registered = {}; | ||
}; | ||
Comment on lines
+314
to
+318
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got the idea here |
||
|
||
props.onComponentsMounted(); | ||
}, []); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and
astro:before-swap
runs only on view transition enabled pages. This will run on load and every page navigation.It mounts all Clerk components in the new document.