Skip to content

Commit

Permalink
Do not use clientLoaders, because they bring more complexity with hyd…
Browse files Browse the repository at this point in the history
…ration issues
  • Loading branch information
fulopkovacs committed Jan 21, 2024
1 parent 8872190 commit 1c26d32
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 65 deletions.
19 changes: 3 additions & 16 deletions app/routes/router.v1.docs.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { FaDiscord, FaGithub } from 'react-icons/fa'
import {
type ClientLoaderFunctionArgs,
Link,
json,
useLoaderData,
} from '@remix-run/react'
import { Link, json, useLoaderData } from '@remix-run/react'
import type { LoaderFunction, MetaFunction } from '@remix-run/node'
import { gradientText, repo, v1branch } from '~/projects/router'
import { seo } from '~/utils/seo'
Expand Down Expand Up @@ -63,22 +58,14 @@ export const meta: MetaFunction = () => {
})
}

export const clientLoader = async ({
serverLoader,
}: ClientLoaderFunctionArgs) => {
const { tanstackDocsConfig } = await serverLoader<typeof loader>()
export default function DocsRoute() {
const { tanstackDocsConfig } = useLoaderData<typeof loader>()

const config = {
...tanstackDocsConfig,
menu: [localMenu, ...tanstackDocsConfig.menu],
}

return config
}

export default function DocsRoute() {
const config = useLoaderData<typeof clientLoader>()

return (
<Docs
{...{
Expand Down
65 changes: 30 additions & 35 deletions app/routes/table.v8.docs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react'
import { FaDiscord, FaGithub } from 'react-icons/fa'
import type { ClientLoaderFunctionArgs } from '@remix-run/react'
import { Link, json, useLoaderData } from '@remix-run/react'
import { gradientText, repo, v8branch } from '~/projects/table'
import { seo } from '~/utils/seo'
Expand All @@ -8,26 +8,6 @@ import { DefaultErrorBoundary } from '~/components/DefaultErrorBoundary'
import type { MetaFunction } from '@remix-run/node'
import { getTanstackDocsConfig } from '~/utils/config'

export const loader = async () => {
const tanstackDocsConfig = await getTanstackDocsConfig(repo, v8branch)

return json({
tanstackDocsConfig,
})
}

const logo = (
<>
<Link to="/" className="font-light">
TanStack
</Link>
<Link to=".." className={`font-bold`}>
<span className={`${gradientText}`}>Table</span>{' '}
<span className="text-sm align-super">v8</span>
</Link>
</>
)

const localMenu = {
label: 'Menu',
children: [
Expand All @@ -54,6 +34,26 @@ const localMenu = {
],
}

export const loader = async () => {
const tanstackDocsConfig = await getTanstackDocsConfig(repo, v8branch)

return json({
tanstackDocsConfig,
})
}

const logo = (
<>
<Link to="/" className="font-light">
TanStack
</Link>
<Link to=".." className={`font-bold`}>
<span className={`${gradientText}`}>Table</span>{' '}
<span className="text-sm align-super">v8</span>
</Link>
</>
)

export const meta: MetaFunction = () => {
return seo({
title:
Expand All @@ -63,23 +63,18 @@ export const meta: MetaFunction = () => {
})
}

export const clientLoader = async ({
serverLoader,
}: ClientLoaderFunctionArgs) => {
const { tanstackDocsConfig } = await serverLoader<typeof loader>()

const config = {
...tanstackDocsConfig,
menu: [localMenu, ...tanstackDocsConfig.menu],
}

return config
}

export const ErrorBoundary = DefaultErrorBoundary

export default function RouteReactTable() {
const config = useLoaderData<typeof clientLoader>()
const { tanstackDocsConfig } = useLoaderData<typeof loader>()

const config = useMemo(
() => ({
...tanstackDocsConfig,
menu: [localMenu, ...tanstackDocsConfig.menu],
}),
[tanstackDocsConfig]
)

return (
<Docs
Expand Down
14 changes: 14 additions & 0 deletions app/routes/table.v8.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import { Link, Outlet, useLocation, useSearchParams } from '@remix-run/react'
import { json } from '@remix-run/node'
import { DefaultErrorBoundary } from '~/components/DefaultErrorBoundary'
import { v8branch } from '~/projects/table'
import { getTanstackDocsConfig } from '~/utils/config'

export const loader = async () => {
const repo = 'tanstack/table'
const tanstackDocsConfig = await getTanstackDocsConfig(repo, v8branch)

return json({
tanstackDocsConfig,
})
}

export type TableConfigLoaderData = typeof loader

export const ErrorBoundary = DefaultErrorBoundary

Expand Down
25 changes: 11 additions & 14 deletions app/routes/virtual.v3.docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Link, json, useLoaderData } from '@remix-run/react'
import { gradientText, repo, v3branch } from '~/projects/virtual'
import { seo } from '~/utils/seo'
import { Docs } from '~/components/Docs'
import type { ClientLoaderFunctionArgs, MetaFunction } from '@remix-run/react'
import type { MetaFunction } from '@remix-run/react'
import { getTanstackDocsConfig } from '~/utils/config'
import { useMemo } from 'react'

export const loader = async () => {
const tanstackDocsConfig = await getTanstackDocsConfig(repo, v3branch)
Expand Down Expand Up @@ -62,21 +63,17 @@ export const meta: MetaFunction = () => {
'Headless UI for virtualizing long scrollable lists with TS/JS, React, Solid, Svelte and Vue',
})
}
export const clientLoader = async ({
serverLoader,
}: ClientLoaderFunctionArgs) => {
const { tanstackDocsConfig } = await serverLoader<typeof loader>()

const config = {
...tanstackDocsConfig,
menu: [localMenu, ...tanstackDocsConfig.menu],
}

return config
}

export default function RouteVirtual() {
const config = useLoaderData<typeof clientLoader>()
const { tanstackDocsConfig } = useLoaderData<typeof loader>()

const config = useMemo(
() => ({
...tanstackDocsConfig,
menu: [localMenu, ...tanstackDocsConfig.menu],
}),
[tanstackDocsConfig]
)

return (
<Docs
Expand Down

0 comments on commit 1c26d32

Please sign in to comment.