Skip to content
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

TSR #199

Merged
merged 43 commits into from
Apr 2, 2024
Merged

TSR #199

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b37ceb0
tsr + vinxi init
tannerlinsley Jan 18, 2024
b8a3daa
checkpoint
tannerlinsley Jan 25, 2024
f721e64
Fix rebase
lachlancollins Jan 28, 2024
aa8b73c
update deps
tannerlinsley Jan 25, 2024
0575674
match.handle => match.staticData
tannerlinsley Jan 25, 2024
b6b7ca0
checkpoint
tannerlinsley Jan 28, 2024
a0ac2b3
fix: link ssr and client router (#167)
nksaraf Jan 28, 2024
3aea88b
fix: upgrade deps
tannerlinsley Jan 30, 2024
1dbac72
feat: checkpoint
tannerlinsley Feb 2, 2024
0a348a1
fix: upgrade deps
tannerlinsley Feb 2, 2024
30f8013
fix: upgrade deps, remove unnecessary default error boundaries
tannerlinsley Feb 2, 2024
97deed9
fix: html level headers support
tannerlinsley Feb 3, 2024
72fd484
checkpoint
tannerlinsley Feb 29, 2024
4788b85
checkpoint
tannerlinsley Mar 1, 2024
967aceb
checkpoint
tannerlinsley Mar 5, 2024
01b1e57
checkpoint
tannerlinsley Mar 5, 2024
f4c9f66
make build work with latest vinxi (#189)
nksaraf Mar 5, 2024
b2b7598
fix: upgrade deps
tannerlinsley Mar 5, 2024
d7fdf46
no build command
tannerlinsley Mar 5, 2024
a1abba2
output directory
tannerlinsley Mar 5, 2024
76a2de4
deploy
tannerlinsley Mar 5, 2024
72b69ee
TanStack Start Teaser
tannerlinsley Mar 5, 2024
9920d01
fix: migrate all routes
tannerlinsley Mar 12, 2024
9954a95
use real packages
tannerlinsley Mar 12, 2024
131fe91
fix: add TanStack Start
tannerlinsley Mar 12, 2024
bfdcfaa
No index for tsr branch
tannerlinsley Mar 12, 2024
fa00e66
rebase
tannerlinsley Mar 14, 2024
8a581b7
Merge branch 'main' into tsr
tannerlinsley Mar 14, 2024
4b456a4
cjs crap
tannerlinsley Mar 14, 2024
00f379b
fix colors, add scroll restoration, fix docsearch
tannerlinsley Mar 14, 2024
ac78d9c
fix: framework/version picker
tannerlinsley Mar 14, 2024
0e2042f
give prism some mb-4
tannerlinsley Mar 14, 2024
a10d58c
fix: ranger => query type
tannerlinsley Mar 14, 2024
e2e2b84
fix: config get started link
tannerlinsley Mar 14, 2024
21125b2
fix: type errors
tannerlinsley Mar 14, 2024
0721b4c
cleanup
tannerlinsley Mar 15, 2024
50dc318
update deps
tannerlinsley Mar 22, 2024
a356096
fix: upgrade deps
tannerlinsley Mar 22, 2024
ff512c8
fix: upgrade deps
tannerlinsley Mar 22, 2024
6a7d3f0
fix: sidebar collapsing and the content badge hitting the link conten…
SeanCassiere Mar 24, 2024
a113684
feat codesplitting
tannerlinsley Mar 29, 2024
a775ab1
Merge branch 'main' into tsr
tannerlinsley Mar 29, 2024
f12622d
fix: documentation upgrade, better 404s, organization
tannerlinsley Apr 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": ["react-app"],
"parser": "@typescript-eslint/parser",
"plugins": ["react-hooks"]
}
12 changes: 0 additions & 12 deletions .eslintrc.cjs

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ yarn.lock
.env
.vercel
.output
.vinxi

/build/
/api/
/server/build
/public/build
.vinxi
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Welcome to TanStack.com!

This site is built with Remix!
This site is built with TanStack Router!

- [Remix Docs](https://remix.run/docs)
- [TanStack Router Docs](https://tanstack.com/router)

It's deployed automagically with Vercel!

Expand All @@ -21,7 +21,7 @@ This starts your app in development mode, rebuilding assets on file changes.

## Editing and previewing the docs of TanStack projects locally

The documentations for all TanStack projects except for `React Charts` are hosted on [https://tanstack.com](https://tanstack.com), powered by this Remix app.
The documentations for all TanStack projects except for `React Charts` are hosted on [https://tanstack.com](https://tanstack.com), powered by this TanStack Router app.
In production, the markdown doc pages are fetched from the GitHub repos of the projects, but in development they are read from the local file system.

Follow these steps if you want to edit the doc pages of a project (in these steps we'll assume it's [`TanStack/form`](https://github.com/tanstack/form)) and preview them locally :
Expand Down
129 changes: 129 additions & 0 deletions app.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { createApp } from 'vinxi'
import reactRefresh from '@vitejs/plugin-react'
import { serverFunctions } from '@vinxi/server-functions/plugin'
import { TanStackRouterVite } from '@tanstack/router-vite-plugin'
import { config } from 'vinxi/plugins/config'
import tsconfigPaths from 'vite-tsconfig-paths'
import { serverTransform } from '@vinxi/server-functions/server'
import { normalize } from 'vinxi/lib/path'
import { resolve } from 'import-meta-resolve'
import path from 'path'
import { fileURLToPath } from 'url'

const customVite = () =>
config('dev', (router, app, env) => ({
// ssr: {
// noExternal: [/react-router-server\/dist\/esm\/server-runtime/],
// },
optimizeDeps: {
include: [
'node_modules@tanstack/react-router-server/**/*.js',
'react-icons',
],
},
resolve:
env.command !== 'build'
? {
dedupe: [
'react',
'react-dom',
'@tanstack/store',
'@tanstack/react-store',
'@tanstack/react-router',
'@tanstack/react-router-server',
'@tanstack/react-cross-context',
'@tanstack/history',
'use-sync-external-store',
],
}
: {},
// plugins: [
// {
// name: 'inline-env-vars-as-prefix',
// // Write the env vars for some specific keys into the bundle at the very beginning of the file
// // using a (globalThis || window).tsr_env object.
// intro: `(globalThis || window).ROUTER_NAME = import.meta.env.ROUTER_NAME`,
// },
// ],
}))

export default createApp({
server: {
preset: 'vercel',
experimental: {
asyncStorage: true,
asyncContext: true,
},
},
routers: [
{
name: 'public',
type: 'static',
dir: './public',
base: '/',
},
{
name: 'ssr',
type: 'http',
handler: './app/server.tsx',
target: 'server',
plugins: () => [
TanStackRouterVite({
experimental: {
enableCodeSplitting: true,
},
}),
customVite(),
tsconfigPaths(),
serverTransform({
runtime: `@tanstack/react-router-server/server-runtime`,
}),
reactRefresh(),
],
link: {
client: 'client',
},
},
{
name: 'client',
type: 'client',
handler: './app/client.tsx',
target: 'browser',
base: '/_build',
plugins: () => [
TanStackRouterVite({
experimental: {
enableCodeSplitting: true,
},
}),
customVite(),
tsconfigPaths(),
serverFunctions.client({
runtime: `@tanstack/react-router-server/client-runtime`,
}),
reactRefresh(),
],
},
serverFunctions.router({
name: 'server',
plugins: () => [customVite(), tsconfigPaths()],
handler: resolveToRelative(
'@tanstack/react-router-server/server-handler'
),
runtime: `@tanstack/react-router-server/server-runtime`,
}),
],
})

function resolveToRelative(p) {
const toAbsolute = (file) => file.split('://').at(-1)

const resolved = toAbsolute(resolve(p, import.meta.url))

const relative = path.relative(
path.resolve(toAbsolute(import.meta.url), '..'),
resolved
)

return relative
}
76 changes: 76 additions & 0 deletions app/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { createCookie } from '@remix-run/node'
import { redirect } from '@tanstack/react-router'

let secret = process.env.COOKIE_SECRET || 'default'
if (secret === 'default') {
console.warn(
'🚨 No COOKIE_SECRET environment variable set, using default. The app is insecure in production.'
)
secret = 'default-secret'
}

let cookie = createCookie('auth', {
secrets: [secret],
// 30 days
maxAge: 30 * 24 * 60 * 60,
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
})

export async function getAuthFromRequest(
request: Request
): Promise<string | null> {
const c = request.headers.get('Cookie')
let userId = await cookie.parse(c)
return userId ?? null
}

export async function setAuthOnResponse(
response: Response,
userId: string
): Promise<Response> {
let header = await cookie.serialize(userId)
response.headers.append('Set-Cookie', header)
return response
}

export async function requireAuthCookie(request: Request) {
let userId = await getAuthFromRequest(request)
if (!userId) {
throw redirect({
to: '/login',
headers: {
'Set-Cookie': await cookie.serialize('', {
maxAge: 0,
}),
},
})
}
return userId
}

export async function redirectIfLoggedInLoader({
request,
}: {
request: Request
}) {
let userId = await getAuthFromRequest(request)
if (userId) {
throw redirect({
to: '/',
})
}
return null
}

export async function redirectWithClearedCookie() {
return redirect({
to: '/',
headers: {
'Set-Cookie': await cookie.serialize(null, {
expires: new Date(0),
}),
},
})
}
13 changes: 13 additions & 0 deletions app/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference types="vinxi/types/client" />
import { hydrateRoot } from 'react-dom/client'
import 'vinxi/client'

import { createRouter } from './router'
import { StartClient } from '@tanstack/react-router-server'

const router = createRouter()

const app = <StartClient router={router} />

router.hydrate()
hydrateRoot(document, app)
6 changes: 4 additions & 2 deletions app/components/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { FaCopy } from 'react-icons/fa'
import { svelteHighlighter } from '~/utils/svelteHighlighter'
// Add back additional language support after `prism-react` upgrade
;(typeof global !== 'undefined' ? global : window).Prism = Prism
require('prismjs/components/prism-diff')
require('prismjs/components/prism-bash')
// @ts-expect-error
import('prismjs/components/prism-diff')
// @ts-expect-error
import('prismjs/components/prism-bash')

// @ts-ignore Alias markup as vue highlight
Prism.languages.vue = Prism.languages.markup
Expand Down
93 changes: 52 additions & 41 deletions app/components/DefaultCatchBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,66 @@
import { Link } from '@remix-run/react'
import {
ErrorComponent,
ErrorComponentProps,
Link,
rootRouteId,
useMatch,
useRouter,
} from '@tanstack/react-router'

type DefaultCatchBoundaryType = {
status: number
statusText: string
data: string
isRoot?: boolean
}
// type DefaultCatchBoundaryType = {
// status: number
// statusText: string
// data: string
// isRoot?: boolean
// }

export function DefaultCatchBoundary({
status,
statusText,
data,
isRoot,
}: DefaultCatchBoundaryType) {
let message
switch (status) {
case 401:
message = (
<p>
Oops! Looks like you tried to visit a page that you do not have access
to.
</p>
)
break
case 404:
message = (
<p>Oops! Looks like you tried to visit a page that does not exist.</p>
)
break
export function DefaultCatchBoundary({ error }: ErrorComponentProps) {
const router = useRouter()
const isRoot = useMatch({
strict: false,
select: (state) => state.id === rootRouteId,
})

default:
throw new Error(data || statusText)
}
console.error(error)

return (
<div className="flex-1 p-4 flex flex-col items-center justify-center gap-6">
<h1 className="opacity-10 flex flex-col text-center font-black">
<div className="text-7xl leading-none">{status}</div>
{/* <div className="text-7xl leading-none">{status}</div>
{statusText ? (
<div className="text-3xl leading-none">{statusText}</div>
) : null}
) : null} */}
</h1>
{message ? <div className="text-lg">{message}</div> : null}
{isRoot ? (
<Link
to="/"
className={`py-2 px-4 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
<ErrorComponent error={error} />
<div className="flex gap-2 items-center flex-wrap">
<button
onClick={() => {
router.invalidate()
}}
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
>
TanStack Home
</Link>
) : null}
Try Again
</button>
{isRoot ? (
<Link
to="/"
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
>
TanStack Home
</Link>
) : (
<Link
to="/"
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
onClick={(e) => {
e.preventDefault()
window.history.back()
}}
>
Go Back
</Link>
)}
</div>
</div>
)
}
Loading
Loading