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(clerk-react,remix,nextjs): Make path the default routing strategy for NextJS and Remix #2338

Conversation

octoper
Copy link
Member

@octoper octoper commented Dec 13, 2023

Description

This PR introduces changes that will make path strategy the default if the path prop is filled for Next.js and Remix frameworks, previously the routing strategy if there is no routing or path prop filled we would fallback to hash routing strategy.

In addition if no path prop is filled an error will be thrown.

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:

Packages affected

  • @clerk/backend
  • @clerk/chrome-extension
  • @clerk/clerk-js
  • @clerk/clerk-expo
  • @clerk/fastify
  • gatsby-plugin-clerk
  • @clerk/localizations
  • @clerk/nextjs
  • @clerk/clerk-react
  • @clerk/remix
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/themes
  • @clerk/types
  • build/tooling/chore

Copy link

changeset-bot bot commented Dec 13, 2023

🦋 Changeset detected

Latest commit: 563f1e7

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

This PR includes changesets to release 8 packages
Name Type
@clerk/clerk-js Major
@clerk/nextjs Major
@clerk/clerk-react Major
@clerk/remix Major
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/elements Patch
gatsby-plugin-clerk 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

@octoper octoper marked this pull request as ready for review December 13, 2023 18:05
@tmilewski tmilewski force-pushed the vaggelis/sdk-663-make-path-based-routing-the-default-for-frameworks-that branch 2 times, most recently from a5ca7a4 to d2d8af4 Compare December 13, 2023 22:06
@tmilewski
Copy link
Member

@octoper I was able to unblock the CI issues, but had to pull work in from main. Seems there's still some, legit, unit tests failing. 👍

@octoper octoper force-pushed the vaggelis/sdk-663-make-path-based-routing-the-default-for-frameworks-that branch from d2d8af4 to 25ff3f5 Compare December 13, 2023 23:09
@octoper octoper force-pushed the vaggelis/sdk-663-make-path-based-routing-the-default-for-frameworks-that branch from 25ff3f5 to 414cbd6 Compare December 14, 2023 07:57
@octoper octoper force-pushed the vaggelis/sdk-663-make-path-based-routing-the-default-for-frameworks-that branch 2 times, most recently from fdad171 to 0327a81 Compare December 14, 2023 08:43
import { errorThrower } from '../errors/errorThrower';
import { noPathProvidedError } from '../errors/messages';

export function withPathDefaultRouting<T, P extends RoutingOptions>(Component: T, componentName: string): T {
Copy link
Contributor

Choose a reason for hiding this comment

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

@dimkl Shall we move this to the new react/internal subpath export?

packages/react/src/errors/messages.ts Outdated Show resolved Hide resolved
@@ -7,7 +7,7 @@ const OrganizationProfilePage: NextPage = () => {
<div
style={{ display: 'flex', flexDirection: 'column', gap: '2rem', justifyContent: 'center', alignItems: 'center' }}
>
<OrganizationProfile />
<OrganizationProfile path='/organization' />
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Will this error on dev time due to missing type?

Copy link
Contributor

Choose a reason for hiding this comment

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

This error will be shown when the component is being rendered. This is a runtime error

} from '@clerk/clerk-react';

export const UserProfile: typeof BaseUserProfile = withPathDefaultRouting(BaseUserProfile, 'UserProfile');
Copy link
Member

Choose a reason for hiding this comment

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

Good job using a HOC for this, but I feel that the types here should just work - why did you need to use typeof here?

Could it be that the type of the HOC itself needs tweaking so the type can be inferred correctly?

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 started seeing an error at some point after this PR, that the types couldn't not be inferred automatically.

@@ -37,6 +54,9 @@ export const SignIn = (props: SignInProps) => {
export const SignUp = (props: SignUpProps) => {
Copy link
Member

Choose a reason for hiding this comment

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

It seems that you're not using the HOC for the components that are mounted in paths we can infer using the env variables.

I feel like we should align this behavior by either:

  • making the Hoc generic enough to support both cases
  • supported env variables for all components

Do you want to discuss offline for possible solutions? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

☝️

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 I thought about that too, but the path of <SignIn/> and <SignUp/> can be also defined from the Clerk options on the <ClerkProvider/> and I didn't know if we wanted to make the changes to have ENV and options for every component.

@dimkl dimkl self-assigned this Dec 15, 2023
@dimkl dimkl force-pushed the vaggelis/sdk-663-make-path-based-routing-the-default-for-frameworks-that branch from cfe4ca0 to 4da9391 Compare December 18, 2023 16:47
@dimkl dimkl force-pushed the vaggelis/sdk-663-make-path-based-routing-the-default-for-frameworks-that branch from 460354b to 0a122e4 Compare December 18, 2023 17:12
@dimkl dimkl force-pushed the vaggelis/sdk-663-make-path-based-routing-the-default-for-frameworks-that branch from 6067887 to c62c439 Compare December 18, 2023 17:24
<OrganizationProfile routing="hash_or_virtual"/>
<SignIn routing="hash_or_virtual"/>
<SignUp routing="hash_or_virtual"/>
```
Copy link
Contributor

Choose a reason for hiding this comment

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

@SokratisVidros , @nikosdouvlis i have also added examples in changeset

@dimkl dimkl force-pushed the vaggelis/sdk-663-make-path-based-routing-the-default-for-frameworks-that branch from c62c439 to 1922a1d Compare December 18, 2023 18:11
@dimkl dimkl force-pushed the vaggelis/sdk-663-make-path-based-routing-the-default-for-frameworks-that branch from 1922a1d to 563f1e7 Compare December 19, 2023 09:04
@dimkl dimkl added this pull request to the merge queue Dec 19, 2023
Merged via the queue into main with commit cfea3d9 Dec 19, 2023
7 checks passed
@dimkl dimkl deleted the vaggelis/sdk-663-make-path-based-routing-the-default-for-frameworks-that branch December 19, 2023 10:56
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.

6 participants