Skip to content

Commit 4e3a4df

Browse files
wobsorianoLekoArts
andauthored
fix(react-router): Update playground & pkg (#4628)
Co-authored-by: LekoArts <[email protected]>
1 parent 4540b05 commit 4e3a4df

File tree

16 files changed

+71
-78
lines changed

16 files changed

+71
-78
lines changed

packages/react-router/package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,27 @@
2727
"exports": {
2828
".": {
2929
"types": "./dist/index.d.ts",
30-
"default": "./dist/index.js"
30+
"import": "./dist/index.mjs",
31+
"require": "./dist/index.js"
3132
},
3233
"./ssr.server": {
3334
"types": "./dist/ssr/index.d.ts",
34-
"default": "./dist/ssr/index.js"
35+
"import": "./dist/ssr/index.mjs",
36+
"require": "./dist/ssr/index.js"
3537
},
3638
"./api.server": {
3739
"types": "./dist/api/index.d.ts",
38-
"default": "./dist/api/index.js"
40+
"import": "./dist/api/index.mjs",
41+
"require": "./dist/api/index.js"
3942
},
4043
"./errors": {
4144
"types": "./dist/errors.d.ts",
42-
"default": "./dist/errors.js"
45+
"import": "./dist/errors.mjs",
46+
"require": "./dist/errors.js"
4347
}
4448
},
4549
"main": "dist/index.js",
50+
"module": "dist/index.mjs",
4651
"types": "dist/index.d.ts",
4752
"typesVersions": {
4853
"*": {
@@ -69,7 +74,8 @@
6974
"dev:publish": "pnpm dev -- --env.publish",
7075
"lint": "eslint src/",
7176
"lint:attw": "attw --pack .",
72-
"lint:publint": "publint"
77+
"lint:publint": "publint",
78+
"publish:local": "pnpm dlx yalc push --replace --sig"
7379
},
7480
"dependencies": {
7581
"@clerk/backend": "workspace:*",
@@ -85,13 +91,13 @@
8591
"@types/node": "^18.19.33",
8692
"@types/react": "catalog:react",
8793
"@types/react-dom": "catalog:react",
88-
"react-router-dom": "7.0.0-pre.6",
94+
"react-router": "7.0.0-pre.6",
8995
"typescript": "catalog:repo"
9096
},
9197
"peerDependencies": {
9298
"react": ">=18",
9399
"react-dom": ">=18",
94-
"react-router": "^7.0.0-pre"
100+
"react-router": "^7.0.0-pre.6"
95101
},
96102
"engines": {
97103
"node": ">=20.0.0"

packages/react-router/src/client/ClerkApp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { useLoaderData } from 'react-router-dom';
2+
import { useLoaderData } from 'react-router';
33

44
import { assertPublishableKeyInSpaMode, inSpaMode } from '../utils';
55
import { ClerkProvider } from './RemixClerkProvider';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './RemixClerkProvider';
22
export { ClerkApp } from './ClerkApp';
3-
export { WithClerkState } from './types';
3+
export type { WithClerkState } from './types';
44
export { SignIn, SignUp } from './uiComponents';

packages/react-router/src/client/useAwaitableNavigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import type { NavigateOptions } from 'react-router';
3-
import { useLocation, useNavigate } from 'react-router-dom';
3+
import { useLocation, useNavigate } from 'react-router';
44

55
type Resolve = (value?: unknown) => void;
66

packages/react-router/src/client/usePathnameWithoutSplatRouteParams.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useLocation, useParams } from 'react-router-dom';
1+
import { useLocation, useParams } from 'react-router';
22

33
export const usePathnameWithoutSplatRouteParams = () => {
44
const params = useParams();

packages/react-router/src/ssr/rootAuthLoader.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { decorateObjectWithResources } from '@clerk/backend/internal';
22

3-
/* TODO(v7): Fix this
4-
import type { defer } from '@remix-run/server-runtime';
5-
import { isDeferredData } from '@remix-run/server-runtime/dist/responses';
6-
*/
3+
// import type { defer } from '@remix-run/server-runtime';
4+
// import { isDeferredData } from '@remix-run/server-runtime/dist/responses';
75
import { invalidRootLoaderCallbackReturn } from '../utils/errors';
86
import { authenticateRequest } from './authenticateRequest';
97
import { loadOptions } from './loadOptions';
108
import type { LoaderFunctionArgs, LoaderFunctionReturn, RootAuthLoaderCallback, RootAuthLoaderOptions } from './types';
11-
import { assertValidHandlerResult, injectRequestStateIntoResponse, isRedirect, isResponse } from './utils';
9+
import {
10+
assertValidHandlerResult,
11+
// injectRequestStateIntoDeferredData,
12+
injectRequestStateIntoResponse,
13+
isRedirect,
14+
isResponse,
15+
} from './utils';
1216

1317
interface RootAuthLoader {
1418
<Options extends RootAuthLoaderOptions, Callback extends RootAuthLoaderCallback<Options>>(
@@ -60,18 +64,15 @@ export const rootAuthLoader: RootAuthLoader = async (
6064
const handlerResult = await handler(args);
6165
assertValidHandlerResult(handlerResult, invalidRootLoaderCallbackReturn);
6266

63-
/* TODO(v7): Fix this
6467
// When using defer(), we need to inject the clerk auth state into its internal data object.
65-
if (isDeferredData(handlerResult)) {
66-
return injectRequestStateIntoDeferredData(
67-
// This is necessary because the DeferredData type is not exported from remix.
68-
// TODO(v7): This is probably incorrect now
69-
handlerResult as unknown as ReturnType<any>,
70-
requestState,
71-
args.context,
72-
);
73-
}
74-
*/
68+
// if (isDeferredData(handlerResult)) {
69+
// return injectRequestStateIntoDeferredData(
70+
// // This is necessary because the DeferredData type is not exported from remix.
71+
// handlerResult as unknown as ReturnType<typeof defer>,
72+
// requestState,
73+
// args.context,
74+
// );
75+
// }
7576

7677
if (isResponse(handlerResult)) {
7778
try {

packages/react-router/src/ssr/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
SignUpFallbackRedirectUrl,
99
SignUpForceRedirectUrl,
1010
} from '@clerk/types';
11-
import type { LoaderFunction } from 'react-router-dom';
11+
import type { DataStrategyFunctionArgs, LoaderFunction } from 'react-router';
1212

1313
export type GetAuthReturn = Promise<AuthObject>;
1414

@@ -62,8 +62,7 @@ type ObjectLike = Record<string, unknown> | null;
6262
*/
6363
export type RootAuthLoaderCallbackReturn = Promise<Response> | Response | Promise<ObjectLike> | ObjectLike;
6464

65-
// TODO(v7): Fix this
66-
export type LoaderFunctionArgs = any;
65+
export type LoaderFunctionArgs = DataStrategyFunctionArgs;
6766
export type LoaderFunctionReturn = ReturnType<LoaderFunction>;
6867

6968
export type LoaderFunctionArgsWithAuth<Options extends RootAuthLoaderOptions = any> = LoaderFunctionArgs & {

packages/react-router/src/ssr/utils.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { constants, debugRequestState } from '@clerk/backend/internal';
22
import { isTruthy } from '@clerk/shared/underscore';
3+
// import type { AppLoadContext, defer } from '@remix-run/server-runtime';
34
import cookie from 'cookie';
4-
import type { AppLoadContext } from 'react-router-dom';
5-
import { json } from 'react-router-dom';
5+
import type { AppLoadContext } from 'react-router';
66

7-
import { getEnvVariable } from '../utils/utils';
7+
// import { json } from 'react-router';
8+
import * as utils from '../utils/utils';
89
import type { RequestStateWithRedirectUrls } from './types';
910

1011
export function isResponse(value: any): value is Response {
@@ -48,11 +49,12 @@ export const injectRequestStateIntoResponse = async (
4849
clone.headers.append(key, value);
4950
});
5051

51-
return json({ ...(data || {}), ...clerkState }, clone);
52+
// return json({ ...(data || {}), ...clerkState }, clone);
53+
return Response.json({ ...(data || {}), ...clerkState }, clone);
5254
};
5355

5456
export function injectRequestStateIntoDeferredData(
55-
data: ReturnType<typeof defer>,
57+
data: ReturnType<any>,
5658
requestState: RequestStateWithRedirectUrls,
5759
context: AppLoadContext,
5860
) {
@@ -65,7 +67,6 @@ export function injectRequestStateIntoDeferredData(
6567
data.init.headers = new Headers(data.init.headers);
6668

6769
headers.forEach((value, key) => {
68-
// @ts-expect-error -- We are ensuring headers is defined above
6970
data.init.headers.append(key, value);
7071
});
7172
}
@@ -95,10 +96,10 @@ export function getResponseClerkState(requestState: RequestStateWithRedirectUrls
9596
__signInFallbackRedirectUrl: requestState.signInFallbackRedirectUrl,
9697
__signUpFallbackRedirectUrl: requestState.signUpFallbackRedirectUrl,
9798
__clerk_debug: debugRequestState(requestState),
98-
__clerkJSUrl: getEnvVariable('CLERK_JS', context),
99-
__clerkJSVersion: getEnvVariable('CLERK_JS_VERSION', context),
100-
__telemetryDisabled: isTruthy(getEnvVariable('CLERK_TELEMETRY_DISABLED', context)),
101-
__telemetryDebug: isTruthy(getEnvVariable('CLERK_TELEMETRY_DEBUG', context)),
99+
__clerkJSUrl: utils.getEnvVariable('CLERK_JS', context),
100+
__clerkJSVersion: utils.getEnvVariable('CLERK_JS_VERSION', context),
101+
__telemetryDisabled: isTruthy(utils.getEnvVariable('CLERK_TELEMETRY_DISABLED', context)),
102+
__telemetryDebug: isTruthy(utils.getEnvVariable('CLERK_TELEMETRY_DEBUG', context)),
102103
});
103104

104105
return {

packages/react-router/src/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AppLoadContext } from 'react-router-dom';
1+
import type { AppLoadContext } from 'react-router';
22

33
import type { ClerkState } from '../client/types';
44
import { invalidClerkStatePropError, noClerkStateError, publishableKeyMissingErrorInSpaMode } from './errors';

packages/react-router/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"baseUrl": ".",
55
"lib": ["es6", "dom"],
66
"jsx": "react",
7-
"module": "NodeNext",
8-
"moduleResolution": "NodeNext",
7+
"module": "ES2020",
8+
"moduleResolution": "Bundler",
99
"importHelpers": true,
1010
"declaration": true,
1111
"declarationMap": false,

packages/react-router/tsup.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ export default defineConfig(overrideOptions => {
1010
const shouldPublish = !!overrideOptions.env?.publish;
1111

1212
const options: Options = {
13-
format: 'cjs',
13+
format: ['cjs', 'esm'],
1414
outDir: './dist',
1515
entry: ['./src/**/*.{ts,tsx,js,jsx}'],
1616
bundle: false,
1717
clean: true,
1818
minify: false,
1919
sourcemap: true,
20-
legacyOutput: true,
20+
legacyOutput: false,
2121
define: {
2222
PACKAGE_NAME: `"${name}"`,
2323
PACKAGE_VERSION: `"${version}"`,

playground/react-router-node/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ node_modules
22

33
/.cache
44
/build
5-
/public/build
65
.env
76

87
.react-router/

playground/react-router-node/app/entry.server.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PassThrough } from 'stream';
1+
import { PassThrough } from 'node:stream';
22
import type { EntryContext } from 'react-router';
33
import { ServerRouter } from 'react-router';
44
import isbot from 'isbot';

playground/react-router-node/app/root.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
import { data, type LoaderFunctionArgs , MetaFunction } from 'react-router';
1+
// import { defer } from 'react-router';
2+
import type { MetaFunction } from 'react-router';
23
import { Await, Links, Meta, Outlet, Scripts, ScrollRestoration, useLoaderData } from 'react-router';
34
import { rootAuthLoader } from '@clerk/react-router/ssr.server';
45
import { ClerkApp } from '@clerk/react-router';
56
import { Suspense } from 'react';
7+
import { DataStrategyFunctionArgs } from 'react-router';
68

7-
export const loader = (args: LoaderFunctionArgs) => {
9+
export const loader = (args: DataStrategyFunctionArgs) => {
810
return rootAuthLoader(
911
args,
1012
async ({ request }) => {
1113
const { user } = request;
14+
const data: Promise<{ foo: string }> = new Promise(r => r({ foo: 'bar' }))
1215

1316
console.log('root User:', user);
1417

15-
return data({ user }, { headers: { 'x-clerk': '1' } })
18+
return Response.json({ user, data }, { headers: { 'x-clerk': '1' } })
1619
},
1720
{ loadUser: true },
1821
);
@@ -26,7 +29,7 @@ export function headers({
2629
parentHeaders: Headers;
2730
}) {
2831
console.log(loaderHeaders)
29-
return loaderHeaders
32+
return loaderHeaders
3033
}
3134

3235
export const meta: MetaFunction = () => {

playground/react-router-node/app/routes/_index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { Route } from "./+types/_index";
1+
import type { LoaderFunction } from 'react-router';
22
import { getAuth } from '@clerk/react-router/ssr.server';
3-
import { ClerkLoaded, SignedIn, useUser } from '@clerk/react-router';
3+
import { ClerkLoaded, SignedIn, useUser, UserButton } from '@clerk/react-router';
44
import { Link } from 'react-router';
55

6-
export async function loader(args: Route.LoaderArgs) {
6+
export async function loader(args: LoaderFunction) {
77
return getAuth(args)
88
}
99

@@ -39,7 +39,7 @@ export default function Index() {
3939
</li>
4040
<li>
4141
SignedIn:
42-
<SignedIn>Signed In!</SignedIn>
42+
<SignedIn><p>You're signed in!</p><UserButton /></SignedIn>
4343
</li>
4444
</ul>
4545
</div>

0 commit comments

Comments
 (0)