-
Notifications
You must be signed in to change notification settings - Fork 283
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: Add react-router SDK #4621
Merged
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
f414fcc
add modified react-router playground app
LekoArts cc77f7d
add initial (unmodified) react-router pkg
LekoArts b0df0a1
get playground working
LekoArts 7fbc46a
more playground updates
LekoArts bcd5231
run codemod on playground for react-router
LekoArts 349b892
use new package
LekoArts 4540b05
update imports
LekoArts 4e3a4df
fix(react-router): Update playground & pkg (#4628)
wobsoriano f538061
remove workspace usage used for debugging
LekoArts dfb3807
add name
LekoArts dcc22e4
add changeset
LekoArts 91c2a5f
remove unused files
LekoArts de98050
remove unused script
LekoArts 74fabec
make pkg ESM-only
LekoArts ead6304
update some remix => react-router instances
LekoArts 2c53767
fix build artifacts
LekoArts 885a9b1
update eslint
LekoArts bd67155
fix routerData
LekoArts fc2ddc3
use declarative routes instead of fs
LekoArts 2b9d829
fix types
LekoArts ef306a6
update packages
LekoArts 94e4944
Merge branch 'main' into lekoarts/eco-247-bootstrap-new-package
LekoArts a033b66
update tsup config
LekoArts 62b7c8e
Use ClerkProvider instead of HoC
LekoArts 57c6675
maybe now correct tsup config?
LekoArts e5a070c
cleanup
LekoArts b8b615c
yey, RR fix
LekoArts 13fa112
Merge branch 'main' into lekoarts/eco-247-bootstrap-new-package
LekoArts 700f48e
improve types
LekoArts a3703f9
Merge branch 'main' into lekoarts/eco-247-bootstrap-new-package
LekoArts 0fd2a70
fix attw linting
LekoArts efb7f0b
add recent remix improvements
LekoArts 7cd4cf5
update README
LekoArts eebfcdd
update types, access __reactRouterContext
LekoArts b9407c1
update isSpaMode
LekoArts bb6953d
update changelog
LekoArts 2fa5342
update renovate
LekoArts c368713
update renovate
LekoArts d7b5253
update renovate workflow
LekoArts e4fdd0e
update renovate workflow
LekoArts de53583
try stuff
LekoArts 488d407
update changeset
LekoArts 295ed51
updates
LekoArts d56e76d
add new playground
LekoArts 106741d
add basic E2E test
LekoArts 91dca0f
inSpaMode -> isSpaMode
LekoArts 5a1b747
add turbo task
LekoArts 01bd359
Merge branch 'main' into lekoarts/eco-247-bootstrap-new-package
LekoArts 622af80
add PORT env var
LekoArts 765213c
use VITE_ prefix
LekoArts 969f0cb
split up utils/utils file
LekoArts d9a35ef
make "isSpaMode" usage more robust
LekoArts 12ddee6
skip e2e tests for now
LekoArts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@clerk/react-router': patch | ||
--- | ||
|
||
Initial beta release of `@clerk/react-router`. | ||
|
||
[React Router v7](https://remix.run/blog/react-router-v7) was released and Clerk's existing `@clerk/remix` SDK isn't compatible anymore. Thus the need for a brand new SDK came up. `@clerk/react-router` allows you to use React Router v7 + Clerk both in framework/library mode. | ||
|
||
Read the [React Router quickstart](https://clerk.com/docs/quickstarts/react-router) and [reference documenation](https://clerk.com/docs/references/react-router/overview) to learn more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { constants } from '../constants'; | ||
import { applicationConfig } from '../models/applicationConfig.js'; | ||
import { templates } from '../templates/index.js'; | ||
|
||
const reactRouterNode = applicationConfig() | ||
.setName('react-router-node') | ||
.useTemplate(templates['react-router-node']) | ||
.setEnvFormatter('public', key => `VITE_${key}`) | ||
.addScript('setup', 'pnpm install') | ||
.addScript('dev', 'pnpm dev') | ||
.addScript('build', 'pnpm build') | ||
.addScript('serve', 'pnpm start') | ||
.addDependency('@clerk/react-router', constants.E2E_CLERK_VERSION || '*'); | ||
|
||
export const reactRouter = { | ||
reactRouterNode, | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.env | ||
!.env.example | ||
.DS_Store | ||
.react-router | ||
build | ||
node_modules | ||
*.tsbuildinfo | ||
.seccorc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# react-router | ||
|
||
Example playground for React Router (Framework mode) and Clerk. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { isRouteErrorResponse, Links, Meta, Outlet, Scripts, ScrollRestoration } from 'react-router'; | ||
import { rootAuthLoader } from '@clerk/react-router/ssr.server'; | ||
import { ClerkProvider } from '@clerk/react-router'; | ||
|
||
import type { Route } from './+types/root'; | ||
|
||
export async function loader(args: Route.LoaderArgs) { | ||
return rootAuthLoader(args); | ||
} | ||
|
||
export function Layout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html lang='en'> | ||
<head> | ||
<meta charSet='utf-8' /> | ||
<meta | ||
name='viewport' | ||
content='width=device-width, initial-scale=1' | ||
/> | ||
<Meta /> | ||
<Links /> | ||
</head> | ||
<body> | ||
{children} | ||
<ScrollRestoration /> | ||
<Scripts /> | ||
</body> | ||
</html> | ||
); | ||
} | ||
|
||
export default function App({ loaderData }: Route.ComponentProps) { | ||
return ( | ||
<ClerkProvider loaderData={loaderData}> | ||
<main> | ||
<Outlet /> | ||
</main> | ||
</ClerkProvider> | ||
); | ||
} | ||
|
||
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) { | ||
let message = 'Oops!'; | ||
let details = 'An unexpected error occurred.'; | ||
let stack: string | undefined; | ||
|
||
if (isRouteErrorResponse(error)) { | ||
message = error.status === 404 ? '404' : 'Error'; | ||
details = error.status === 404 ? 'The requested page could not be found.' : error.statusText || details; | ||
} else if (import.meta.env.DEV && error && error instanceof Error) { | ||
details = error.message; | ||
stack = error.stack; | ||
} | ||
|
||
return ( | ||
<main> | ||
<h1>{message}</h1> | ||
<p>{details}</p> | ||
{stack && ( | ||
<pre> | ||
<code>{stack}</code> | ||
</pre> | ||
)} | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { type RouteConfig, index, route } from '@react-router/dev/routes'; | ||
|
||
export default [ | ||
index('routes/home.tsx'), | ||
route('sign-in/*', 'routes/sign-in.tsx'), | ||
route('sign-up/*', 'routes/sign-up.tsx'), | ||
route('protected', 'routes/protected.tsx'), | ||
] satisfies RouteConfig; |
16 changes: 16 additions & 0 deletions
16
integration/templates/react-router-node/app/routes/home.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { SignedIn, SignedOut, UserButton } from '@clerk/react-router'; | ||
import type { Route } from './+types/home'; | ||
|
||
export function meta({}: Route.MetaArgs) { | ||
return [{ title: 'New React Router App' }, { name: 'description', content: 'Welcome to React Router!' }]; | ||
} | ||
|
||
export default function Home() { | ||
return ( | ||
<div> | ||
<UserButton /> | ||
<SignedIn>SignedIn</SignedIn> | ||
<SignedOut>SignedOut</SignedOut> | ||
</div> | ||
); | ||
} |
21 changes: 21 additions & 0 deletions
21
integration/templates/react-router-node/app/routes/protected.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { redirect } from 'react-router'; | ||
import { getAuth } from '@clerk/react-router/ssr.server'; | ||
import type { Route } from './+types/profile'; | ||
|
||
export async function loader(args: Route.LoaderArgs) { | ||
const { userId } = await getAuth(args); | ||
|
||
if (!userId) { | ||
return redirect('/sign-in?redirect_url=' + args.request.url); | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
export default function Profile(args: Route.ComponentProps) { | ||
return ( | ||
<div> | ||
<h1>Protected</h1> | ||
</div> | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
integration/templates/react-router-node/app/routes/sign-in.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { SignIn } from '@clerk/react-router'; | ||
|
||
export default function SignInPage() { | ||
return ( | ||
<div> | ||
<h1>Sign In route</h1> | ||
<SignIn | ||
routing={'path'} | ||
path={'/sign-in'} | ||
signUpUrl={'/sign-up'} | ||
/> | ||
</div> | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
integration/templates/react-router-node/app/routes/sign-up.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { SignUp } from '@clerk/react-router'; | ||
|
||
export default function SignUpPage() { | ||
return ( | ||
<div> | ||
<h1>Sign Up route</h1> | ||
<SignUp | ||
routing={'path'} | ||
path={'/sign-up'} | ||
signInUrl={'/sign-in'} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "clerk-react-router-quickstart", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build": "react-router build", | ||
"dev": "react-router dev --port $PORT", | ||
"start": "react-router-serve ./build/server/index.js", | ||
"typecheck": "react-router typegen && tsc --build --noEmit" | ||
}, | ||
"dependencies": { | ||
"@clerk/react-router": "latest", | ||
"@react-router/node": "^7.0.2", | ||
"@react-router/serve": "^7.0.2", | ||
"isbot": "^5.1.17", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"react-router": "^7.0.2" | ||
}, | ||
"devDependencies": { | ||
"@react-router/dev": "^7.0.2", | ||
"@types/node": "^20", | ||
"@types/react": "^18.3.12", | ||
"@types/react-dom": "^18.3.1", | ||
"typescript": "^5.6.3", | ||
"vite": "^5.4.11", | ||
"vite-tsconfig-paths": "^5.1.2" | ||
} | ||
} |
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
integration/templates/react-router-node/react-router.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Config } from '@react-router/dev/config'; | ||
|
||
export default { | ||
// Config options... | ||
// Server-side render by default, to enable SPA mode set this to `false` | ||
ssr: true, | ||
} satisfies Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"include": ["**/*", "**/.server/**/*", "**/.client/**/*", ".react-router/types/**/*"], | ||
"compilerOptions": { | ||
"lib": ["DOM", "DOM.Iterable", "ES2022"], | ||
"types": ["node", "vite/client"], | ||
"target": "ES2022", | ||
"module": "ES2022", | ||
"moduleResolution": "bundler", | ||
"jsx": "react-jsx", | ||
"rootDirs": [".", "./.react-router/types"], | ||
"baseUrl": ".", | ||
"paths": { | ||
"~/*": ["./app/*"] | ||
}, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"strict": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { reactRouter } from '@react-router/dev/vite'; | ||
import { defineConfig } from 'vite'; | ||
import tsconfigPaths from 'vite-tsconfig-paths'; | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
reactRouter(), | ||
tsconfigPaths({ | ||
projects: ['./tsconfig.json'], | ||
}), | ||
], | ||
server: { | ||
port: Number(process.env.PORT), | ||
}, | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous version didn't work so I just reverted the pnpm change here