Skip to content

feat(elements): Infer base path - #3557

Merged
LekoArts merged 9 commits into
mainfrom
lekoarts/sdk-1791-infer-base-path-of-flows
Jun 14, 2024
Merged

feat(elements): Infer base path#3557
LekoArts merged 9 commits into
mainfrom
lekoarts/sdk-1791-infer-base-path-of-flows

Conversation

@LekoArts

@LekoArts LekoArts commented Jun 12, 2024

Copy link
Copy Markdown
Contributor

Description

The path prop on the <SignIn.Root> and <SignUp.Root> component is now automatically inferred. Previously, the default values were /sign-in and /sign-up, on other routes you had to explicitly define your route.

The new heuristic for determining the path where <SignIn.Root> and <SignUp.Root> are mounted is:

  1. path prop
  2. Automatically inferred
  3. If it can't be inferred, fallback to CLERK_SIGN_IN_URL and CLERK_SIGN_UP_URL env var
  4. Fallback to /sign-in and /sign-up

Fixes SDK-1791

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:

@changeset-bot

changeset-bot Bot commented Jun 12, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3567e14

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

This PR includes changesets to release 1 package
Name Type
@clerk/elements 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

*
* TODO: re-use usePathnameWithoutCatchAll from the next SDK
* The base path for your sign-in route.
* Will be automatically inferred in Next.js.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the future we can adjust this line e.g. with Remix once we support this in other frameworks, too

Comment on lines +100 to +103
exampleMode = false,
fallback = null,
path = SIGN_IN_DEFAULT_BASE_PATH,
routing,
path: pathProp,
routing = ROUTING.path,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made the falsy exampleMode and routing props more explicit by setting the default values they'd be inferred to anyways

@@ -0,0 +1,61 @@
import { useRouter } from 'next/compat/router';
import { useParams, usePathname } from 'next/navigation';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So in packages/nextjs/src/client-boundary/hooks/usePathnameWithoutCatchAll.tsx we require these two hooks since the inline comment there says that they'd error out in pages router.

I found this papertrail:

  1. Using the pathname ( available through usePathname() hook ) in the /pages router vercel/next.js#62880 (comment)
  2. The useSearchParams() and useParams() hooks behave inconsistently between app and page router vercel/next.js#54242
  3. Make useSearchParams and useParams compatible between app and pages router vercel/next.js#55280
  4. https://github.com/vercel/next.js/blob/4398e348ee724d88282881137311680ee60fb23c/packages/next/navigation-types/compat/navigation.d.ts#L13-L20

So I think we're good with importing it directly since the version that got introduced is below our minimum Next.js version

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, does that mean we can update the one within the nextjs package as well ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, probably. But it works in that setup so "don't change a running system"

'react/sign-up/index': 'src/react/sign-up/index.ts',
},
external: ['react', 'react-dom', '@statelyai/inspect'],
external: ['react', 'react-dom', 'next', '@statelyai/inspect'],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

While https://tsup.egoist.dev/#excluding-packages explains

but dependencies and peerDependencies in your package.json are always excluded

I guess it doesn't hurt explicitly adding it here if we have react and react-dom here already

@LekoArts
LekoArts marked this pull request as ready for review June 12, 2024 12:59
@LekoArts
LekoArts merged commit b8acf30 into main Jun 14, 2024
@LekoArts
LekoArts deleted the lekoarts/sdk-1791-infer-base-path-of-flows branch June 14, 2024 07:07
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.

4 participants