Skip to content

Commit

Permalink
chore(elements): Revert specific SignIn.Root updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilewski committed Oct 4, 2024
1 parent d0e4c86 commit ab1b18c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export const SignInRouterMachine = setup({
resendable: false,
resendableAfter: RESENDABLE_COUNTDOWN_DEFAULT,
}),

setActive: ({ context, event }) => {
if (context.exampleMode) {
return;
Expand Down
49 changes: 24 additions & 25 deletions packages/elements/src/react/sign-in/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,17 @@ type SignInFlowProviderProps = {
*/
fallback?: React.ReactNode;
isRootPath: boolean;

/**
* The base path for your sign-in route.
* Will be automatically inferred in Next.js.
* @example `/sign-in`
*/
path?: string;
/**
* If you want to render Clerk Elements in e.g. a modal, use the `virtual` routing mode.
*/
routing?: ROUTING;
};

const actor = createActor(SignInRouterMachine, { inspect });
actor.start();

function SignInFlowProvider({ children, exampleMode, fallback, isRootPath, path, routing }: SignInFlowProviderProps) {
function SignInFlowProvider({ children, exampleMode, fallback, isRootPath }: SignInFlowProviderProps) {
const clerk = useClerk();
const router = useClerkRouter();
const formRef = useFormStore();

const isReady = useSelector(actor, state => state.value !== 'Idle');

clerk.telemetry?.record(
eventComponentMounted('Elements_SignInRoot', {
exampleMode: exampleMode || false,
fallback: Boolean(fallback),
path: path || false,
routing: routing || false,
}),
);

useEffect(() => {
if (!clerk || !router) {
return;
Expand Down Expand Up @@ -104,7 +83,18 @@ function SignInFlowProvider({ children, exampleMode, fallback, isRootPath, path,
);
}

export type SignInRootProps = Omit<SignInFlowProviderProps, 'isRootPath'>;
export type SignInRootProps = Omit<SignInFlowProviderProps, 'isRootPath'> & {
/**
* The base path for your sign-in route.
* Will be automatically inferred in Next.js.
* @example `/sign-in`
*/
path?: string;
/**
* If you want to render Clerk Elements in e.g. a modal, use the `virtual` routing mode.
*/
routing?: ROUTING;
};

/**
* Root component for the sign-in flow. It sets up providers and state management for its children.
Expand All @@ -129,8 +119,19 @@ export function SignInRoot({
path: pathProp,
routing = ROUTING.path,
}: SignInRootProps): JSX.Element | null {
const clerk = useClerk();
const inferredPath = usePathnameWithoutCatchAll();
const path = pathProp || inferredPath || SIGN_IN_DEFAULT_BASE_PATH;

clerk.telemetry?.record(
eventComponentMounted('Elements_SignInRoot', {
exampleMode,
fallback: Boolean(fallback),
path,
routing,
}),
);

const router = (routing === ROUTING.virtual ? useVirtualRouter : useClerkHostRouter)();
const isRootPath = path === router.pathname();

Expand All @@ -144,8 +145,6 @@ export function SignInRoot({
exampleMode={exampleMode}
fallback={fallback}
isRootPath={isRootPath}
path={path}
routing={routing}
>
{children}
</SignInFlowProvider>
Expand Down

0 comments on commit ab1b18c

Please sign in to comment.