From 7c5e26972fac4f3d2e78df2fc787fb786237956f Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Wed, 10 Jan 2024 01:41:00 +0200 Subject: [PATCH 1/2] fix(clerk-react): Fix routing strategy priority when it's directly passed to the component --- .../__snapshots__/useRoutingProps.test.tsx.snap | 12 +++++++++++- .../src/hooks/__tests__/useRoutingProps.test.tsx | 16 ++++++++++++++++ packages/react/src/hooks/useRoutingProps.ts | 12 ++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/react/src/hooks/__tests__/__snapshots__/useRoutingProps.test.tsx.snap b/packages/react/src/hooks/__tests__/__snapshots__/useRoutingProps.test.tsx.snap index 6a3c65cd32b..f9d8f442466 100644 --- a/packages/react/src/hooks/__tests__/__snapshots__/useRoutingProps.test.tsx.snap +++ b/packages/react/src/hooks/__tests__/__snapshots__/useRoutingProps.test.tsx.snap @@ -14,7 +14,17 @@ exports[`useRoutingProps() returns passed props and options if path is passed fr
- {"path":"/aloha","prop1":"1","prop2":"2"} + {"path":"/aloha","prop1":"1","prop2":"2","routing":"path"} +
+
+ +`; + +exports[`useRoutingProps() returns passed props but omits path prop if path is passed from routing options and a routing strategy other than path is specified 1`] = ` + +
+
+ {"prop1":"1","prop2":"2","routing":"virtual"}
diff --git a/packages/react/src/hooks/__tests__/useRoutingProps.test.tsx b/packages/react/src/hooks/__tests__/useRoutingProps.test.tsx index cfed6f065cd..2afcf9065e7 100644 --- a/packages/react/src/hooks/__tests__/useRoutingProps.test.tsx +++ b/packages/react/src/hooks/__tests__/useRoutingProps.test.tsx @@ -71,4 +71,20 @@ describe('useRoutingProps()', () => { ); expect(baseElement).toMatchSnapshot(); }); + + it('returns passed props but omits path prop if path is passed from routing options and a routing strategy other than path is specified', () => { + const TestingComponent = props => { + const options = useRoutingProps('TestingComponent', props, { path: '/aloha' }); + return
{JSON.stringify(options)}
; + }; + + const { baseElement } = render( + , + ); + expect(baseElement).toMatchSnapshot(); + }); }); diff --git a/packages/react/src/hooks/useRoutingProps.ts b/packages/react/src/hooks/useRoutingProps.ts index e3eac284719..5be76871149 100644 --- a/packages/react/src/hooks/useRoutingProps.ts +++ b/packages/react/src/hooks/useRoutingProps.ts @@ -8,12 +8,20 @@ export function useRoutingProps( props: T, routingOptions?: RoutingOptions, ): T { - const path = routingOptions?.path || props.path; + const path = props.path || routingOptions?.path; if (!path && !props.routing) { errorThrower.throw(noPathProvidedError(componentName)); } - if (props.path) { + if (props.routing && props.routing !== 'path' && routingOptions?.path && !props.path) { + return { + ...routingOptions, + ...props, + path: undefined, + }; + } + + if (path && !props.routing) { return { ...routingOptions, ...props, From 395f16b72d5e674637cbc0848818978874ce4e41 Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Wed, 10 Jan 2024 01:41:44 +0200 Subject: [PATCH 2/2] chore(repo): Add Changeset --- .changeset/tender-phones-explain.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/tender-phones-explain.md diff --git a/.changeset/tender-phones-explain.md b/.changeset/tender-phones-explain.md new file mode 100644 index 00000000000..b95ae585096 --- /dev/null +++ b/.changeset/tender-phones-explain.md @@ -0,0 +1,6 @@ +--- +'@clerk/clerk-react': patch +--- + +Fixes error when path is passed from context and a routing strategy other than `path` is passed as a prop. +This change affects components ``, `` from `@clerk/nextjs` and `@clerk/remix`.