-
-
Notifications
You must be signed in to change notification settings - Fork 6
docs: reorganize plugin-first TanStack Start docs #784
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ import { TypeTable } from 'fumadocs-ui/components/type-table' | |
|
|
||
| Three values, and a `<div>` for the widget to land in. | ||
|
|
||
| ```tsx title="src/site/contact/contact-form.tsx" | ||
| ```tsx title="plugins/contact/src/views/contact/contact-form.tsx" | ||
| import type React from 'react' | ||
|
|
||
| import { useCaptcha } from '@vitnode/core/hooks/use-captcha' // [!code ++] | ||
|
|
@@ -129,31 +129,16 @@ export const createContactRoute = buildRoute({ | |
| </Step> | ||
| <Step> | ||
|
|
||
| ### Read the deployment's config | ||
| ### Read the deployment's config in the plugin screen | ||
|
|
||
| The site key is public, and `middlewareConfigQueryOptions()` is the read as a | ||
| TanStack Query definition. Warm it in the route's `loader` so the widget is not | ||
| waiting on a request after hydration. | ||
| The site key is public. A plugin page can read it with the shared TanStack Query | ||
| definition before rendering its form: | ||
|
Comment on lines
+134
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Keep a loader-backed read for AGENTS.md reference: AGENTS.md:L44-L44 Useful? React with 👍 / 👎. |
||
|
|
||
| ```tsx title="src/routes/_main/contact.tsx" | ||
| import { createFileRoute } from '@tanstack/react-router' | ||
| import { middlewareConfigQueryOptions } from '@vitnode/core/tanstack/auth' // [!code ++] | ||
|
|
||
| import { ContactScreen } from '#/site/contact/contact-screen' | ||
|
|
||
| export const Route = createFileRoute('/_main/contact')({ | ||
| // [!code ++:2] | ||
| loader: async ({ context }) => | ||
| await context.queryClient.ensureQueryData(middlewareConfigQueryOptions()), | ||
| component: ContactScreen, | ||
| }) | ||
| ``` | ||
|
|
||
| ```tsx title="src/site/contact/contact-screen.tsx" | ||
| ```tsx title="plugins/contact/src/routes/contact-page.tsx" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In this newly converted plugin-route snippet, Useful? React with 👍 / 👎. |
||
| import { useSuspenseQuery } from '@tanstack/react-query' | ||
| import { middlewareConfigQueryOptions } from '@vitnode/core/tanstack/auth' | ||
|
|
||
| import { ContactForm } from './contact-form' | ||
| import { ContactForm } from '../views/contact-form' | ||
|
|
||
| export const ContactScreen = () => { | ||
| const { data: config } = useSuspenseQuery(middlewareConfigQueryOptions()) | ||
|
|
@@ -243,11 +228,11 @@ A minimal captcha-gated feature is four files, and only one of them knows the | |
| hook exists. | ||
|
|
||
| <Files> | ||
| <Folder defaultOpen name="src"> | ||
| <Folder defaultOpen name="routes/_main"> | ||
| <File name="contact.tsx" /> | ||
| <Folder defaultOpen name="plugins/contact/src"> | ||
| <Folder defaultOpen name="routes"> | ||
| <File name="contact-page.tsx" /> | ||
| </Folder> | ||
| <Folder defaultOpen name="site/contact"> | ||
| <Folder defaultOpen name="views/contact"> | ||
| <File name="contact-screen.tsx" /> | ||
| <File name="contact-form.tsx" /> | ||
| <File name="send-message.ts" /> | ||
|
|
||
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.
When this example is followed, the loader's response is stored only as plugin
loaderData, while the screen ignores that value and starts a separateuseSuspenseQuery; the loader therefore does not warm the advertised query key and SSR or navigation can fetch the announcements twice. Seed the same query entry before rendering, or pass the loader result to the query as initial data/readloaderDatadirectly.AGENTS.md reference: AGENTS.md:L44-L44
Useful? React with 👍 / 👎.