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): Add CSR support #3911

Merged

Conversation

wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Aug 6, 2024

Description

This PR adds support for static and hybrid outputs in Astro by making our control components isomorphic. A basic e2e test has been added as well.

Limitations:

  • For hybrid output, a isStatic prop is available to control which component to use. It's going to use CSR components by default (since pages are prerendered by default in hybrid output).
  • Have to separate the web components to their own files instead of putting them inside the *CSR.astro components because of some Vite issues. Please see ECO-17 for more info. Fixed here

Closes ECO-17

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 Aug 6, 2024

🦋 Changeset detected

Latest commit: aadf639

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

This PR includes changesets to release 1 package
Name Type
@clerk/astro Minor

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 force-pushed the rob/eco-17-explore-our-options-for-csr-only-support-in-astro branch from 9daf40b to c892565 Compare August 6, 2024 20:48
@wobsoriano wobsoriano force-pushed the rob/eco-17-explore-our-options-for-csr-only-support-in-astro branch from cf4f5c6 to ecaac43 Compare August 8, 2024 00:16
@wobsoriano wobsoriano changed the base branch from main to rob/eco-4-move-or-use-utilities-from-clerkshared August 8, 2024 16:37
@wobsoriano wobsoriano force-pushed the rob/eco-17-explore-our-options-for-csr-only-support-in-astro branch from 8bfae44 to 39df490 Compare August 8, 2024 16:37
Base automatically changed from rob/eco-4-move-or-use-utilities-from-clerkshared to main August 9, 2024 14:14
@wobsoriano wobsoriano force-pushed the rob/eco-17-explore-our-options-for-csr-only-support-in-astro branch from 1b466bd to 3fec45b Compare August 9, 2024 14:25
@clerk clerk deleted a comment from clerk-cookie Aug 12, 2024
@clerk clerk deleted a comment from clerk-cookie Aug 20, 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.1.0-snapshot.v17a4abb
@clerk/backend 1.7.0-snapshot.v17a4abb
@clerk/chrome-extension 1.2.2-snapshot.v17a4abb
@clerk/clerk-js 5.15.0-snapshot.v17a4abb
@clerk/dev-cli 0.0.7-snapshot.v17a4abb
@clerk/elements 0.14.0-snapshot.v17a4abb
@clerk/clerk-expo 2.2.0-snapshot.v17a4abb
@clerk/express 0.0.29-snapshot.v17a4abb
@clerk/fastify 1.0.31-snapshot.v17a4abb
@clerk/localizations 2.6.0-snapshot.v17a4abb
@clerk/nextjs 5.3.2-snapshot.v17a4abb
@clerk/clerk-react 5.4.2-snapshot.v17a4abb
@clerk/remix 4.2.15-snapshot.v17a4abb
@clerk/clerk-sdk-node 5.0.28-snapshot.v17a4abb
@clerk/shared 2.5.2-snapshot.v17a4abb
@clerk/tanstack-start 0.2.2-snapshot.v17a4abb
@clerk/testing 1.2.11-snapshot.v17a4abb
@clerk/themes 2.1.21-snapshot.v17a4abb
@clerk/types 4.14.0-snapshot.v17a4abb

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/dev-cli

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

*
* $isLoadedStore.subscribe((authloaded => console.log(loaded))
*/
export const $isLoadedStore = computed([$csrState], state => state.isLoaded);
Copy link
Member

Choose a reason for hiding this comment

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

What's the reliability issue with $clerkStore ?

Copy link
Member

Choose a reason for hiding this comment

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

This could be added as JSdoc for other maintainers


<style>
clerk-signed-out[hidden] {
display: none !important;
Copy link
Member

Choose a reason for hiding this comment

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

In case someone would like to animate in/out the children of <SignedOut/> would this be possible ?

Copy link
Member Author

@wobsoriano wobsoriano Aug 21, 2024

Choose a reason for hiding this comment

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

Updated the control components to have class props so they can override it. We'll mention this in the CSR reference docs when added 👍🏼

If only there's a way to not have a wrapper element and dynamically render the contents, but sadly no because of how astro components works

permission?: never;
};
import { isStaticOutput } from "virtual:@clerk/astro/config";
import type { ProtectProps } from '../../types';
Copy link
Member

Choose a reason for hiding this comment

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

Does this work because we now expose @clerk/astro/types ?

Copy link
Member Author

@wobsoriano wobsoriano Aug 21, 2024

Choose a reason for hiding this comment

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

We are only copying the types.ts file to so that it can still be resolvable when published. We don't export the types in package.json still, though. I don't see any helpful type to export 🤔

@@ -20,6 +20,9 @@ const astroNode = applicationConfig()
.addDependency('@clerk/types', clerkTypesLocal)
.addDependency('@clerk/localizations', clerkLocalizationLocal);

const astroStatic = astroNode.clone().setName('astro-static').useTemplate(templates['astro-static']);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to add an e2e template with hybrid and prerender = true ?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good to have but I think if we do hybrid test we can have both prerendered pages and just remove static e2e

Copy link
Member Author

@wobsoriano wobsoriano Aug 21, 2024

Choose a reason for hiding this comment

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

Removed static test in favor of hybrid output test

Copy link
Member

@panteliselef panteliselef left a comment

Choose a reason for hiding this comment

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

Great work !!

Copy link
Member

@octoper octoper left a comment

Choose a reason for hiding this comment

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

Great work! 🔥

@wobsoriano wobsoriano merged commit e3cd92b into main Aug 22, 2024
18 checks passed
@wobsoriano wobsoriano deleted the rob/eco-17-explore-our-options-for-csr-only-support-in-astro branch August 22, 2024 12:08
brkalow pushed a commit that referenced this pull request Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants