Skip to content
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

Closed
wants to merge 14 commits into from

Conversation

wobsoriano
Copy link
Member

Description

Checklist

  • npm test runs as expected.
  • npm run 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 Oct 16, 2024

🦋 Changeset detected

Latest commit: 7915b29

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

This PR includes changesets to release 4 packages
Name Type
@clerk/astro Minor
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo 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

@wobsoriano wobsoriano changed the title chore(astro,clerk-js): View transitions support feat(astro,clerk-js): View transitions support Oct 16, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 16, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 16, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 16, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 16, 2024
@clerk clerk deleted a comment from clerk-cookie Oct 16, 2024
@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/astro 1.3.15-snapshot.v78908b6
@clerk/backend 1.14.0-snapshot.v78908b6
@clerk/chrome-extension 1.3.20-snapshot.v78908b6
@clerk/clerk-js 5.27.0-snapshot.v78908b6
@clerk/elements 0.16.2-snapshot.v78908b6
@clerk/clerk-expo 2.2.26-snapshot.v78908b6
@clerk/express 1.3.0-snapshot.v78908b6
@clerk/fastify 2.0.2-snapshot.v78908b6
@clerk/localizations 3.3.0-snapshot.v78908b6
@clerk/nextjs 5.7.4-snapshot.v78908b6
@clerk/clerk-react 5.12.0-snapshot.v78908b6
@clerk/remix 4.2.38-snapshot.v78908b6
@clerk/clerk-sdk-node 5.0.51-snapshot.v78908b6
@clerk/shared 2.9.2-snapshot.v78908b6
@clerk/tanstack-start 0.4.14-snapshot.v78908b6
@clerk/testing 1.3.12-snapshot.v78908b6
@clerk/themes 2.1.37-snapshot.v78908b6
@clerk/types 4.26.0-snapshot.v78908b6

Tip: Use the snippet copy button below to quickly install the required packages.
@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/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/clerk-react

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

@clerk/remix

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

@clerk/clerk-sdk-node

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

@clerk/shared

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

@clerk/tanstack-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

* For more info on the issue, see:
* https://github.com/withastro/astro/issues/11000
*/
__internal_flushEmotionCache() {
Copy link
Member Author

@wobsoriano wobsoriano Oct 17, 2024

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Comment on lines +314 to +318
componentsControls.flushEmotionCache = () => {
emotionCache.sheet.flush();
emotionCache.inserted = {};
emotionCache.registered = {};
};
Copy link
Member Author

Choose a reason for hiding this comment

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

I got the idea here

Comment on lines +120 to +122
document.addEventListener('astro:page-load', async () => {
await runInjectionScript(${JSON.stringify(internalParams)});
})`,
Copy link
Member Author

@wobsoriano wobsoriano Oct 17, 2024

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.

Comment on lines 116 to 118
document.addEventListener('astro:before-swap', async e => {
window.Clerk.__internal_flushEmotionCache();
});
Copy link
Member Author

@wobsoriano wobsoriano Oct 17, 2024

Choose a reason for hiding this comment

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

This event will run before the new document replaces the current document.

The __internal_flushEmotionCache function fixes the issue where mounted components in the next document don't have styles. See implementation here

@wobsoriano wobsoriano closed this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants