Skip to content

Commit

Permalink
single fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtsam committed Dec 26, 2024
1 parent bcf886c commit d7a09bd
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function handleRequest(
context={remixContext}
url={request.url}
abortDelay={ABORT_DELAY}
nonce={nonce}
/>
</NonceProvider>,

Expand Down
4 changes: 2 additions & 2 deletions app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
json,
data,
type MetaFunction,
type LinksFunction,
type LoaderFunctionArgs,
Expand Down Expand Up @@ -91,7 +91,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {

const toast = await getToast(request)

return json(
return data(
{
user,
env: publicEnv,
Expand Down
8 changes: 4 additions & 4 deletions app/routes/_auth+/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { type SEOHandle } from '@nasa-gcn/remix-seo'
import {
type ActionFunctionArgs,
type LoaderFunctionArgs,
json,
data,
redirect,
} from '@remix-run/node'
import { Form, useActionData, useLoaderData } from '@remix-run/react'
Expand Down Expand Up @@ -58,13 +58,13 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {

const prefill = profile

return json({
return {
email: profile.email,
prefillResult: {
initialValue: prefill,
error: {},
} satisfies SubmissionResult,
})
}
}

export const action = async ({ request }: ActionFunctionArgs) => {
Expand Down Expand Up @@ -105,7 +105,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
})

if (submission.status !== 'success') {
return json(
return data(
{ result: submission.reply() },
{ status: submission.status === 'error' ? 400 : 200 },
)
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_site+/blog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, type HeadersFunction, type MetaFunction } from '@remix-run/node'
import { data, type HeadersFunction, type MetaFunction } from '@remix-run/node'
import { Link, useLoaderData } from '@remix-run/react'
import { type PostInfo, getPostInfos } from '#app/utils/mdx/blog.server.ts'
import { pipeHeaders } from '#app/utils/remix.server.ts'
Expand All @@ -20,7 +20,7 @@ export const loader = async () => {
const posts = await getPostInfos()
timing.timeEnd('get posts')

return json(
return data(
{ posts },
{
headers: {
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_site+/blog_.$slug.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import {
json,
data,
type HeadersFunction,
type LoaderFunctionArgs,
type MetaFunction,
Expand Down Expand Up @@ -57,7 +57,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
const meta = getPostMeta(mdxBundle.source)
timing.timeEnd('get post meta')

return json(
return data(
{
code,
meta,
Expand Down
6 changes: 3 additions & 3 deletions app/routes/_user+/settings.profile.connections.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import {
json,
data,
type MetaFunction,
type LoaderFunctionArgs,
type ActionFunctionArgs,
Expand Down Expand Up @@ -76,7 +76,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
const timing = new ServerTiming()
const connections = await getConnections(userId, timing)

return json(
return data(
{ connections },
{ headers: { 'Server-Timing': timing.toString() } },
)
Expand Down Expand Up @@ -280,5 +280,5 @@ const deleteConnection = async ({ formData }: ActionArgs) => {

await db.delete(connectionTable).where(eq(connectionTable.id, connectionId))

return json({ status: 'success' } as const)
return { status: 'success' } as const
}
5 changes: 2 additions & 3 deletions app/routes/_user+/settings.profile.sessions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import {
json,
type MetaFunction,
type ActionFunctionArgs,
type LoaderFunctionArgs,
Expand Down Expand Up @@ -51,7 +50,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
}

const sessionsCount = await getSessionsCount({ userId, sessionId })
return json({ sessionsCount })
return { sessionsCount }
}

type ActionArgs = {
Expand Down Expand Up @@ -162,5 +161,5 @@ const signOutOtherSessions = async ({ request }: ActionArgs) => {
),
)

return json({ status: 'success' } as const)
return { status: 'success' } as const
}
6 changes: 3 additions & 3 deletions app/utils/theme.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseWithZod } from '@conform-to/zod'
import { json } from '@remix-run/node'
import { data } from '@remix-run/node'
import { parse as parseCookie, serialize as serializeCookie } from 'cookie'
import { ThemeFormSchema } from './theme.tsx'

Expand Down Expand Up @@ -29,7 +29,7 @@ export const setTheme = async (formData: FormData) => {
})

if (submission.status !== 'success') {
return json(
return data(
{ result: submission.reply() },
{ status: submission.status === 'error' ? 400 : 200 },
)
Expand All @@ -40,5 +40,5 @@ export const setTheme = async (formData: FormData) => {
const responseInit = {
headers: { 'set-cookie': setThemeCookie(theme) },
}
return json({ result: submission.reply() }, responseInit)
return data({ result: submission.reply() }, responseInit)
}
7 changes: 7 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { sentryVitePlugin } from '@sentry/vite-plugin'
import { defineConfig } from 'vite'
import { envOnlyMacros } from 'vite-env-only'

declare module '@remix-run/node' {
interface Future {
v3_singleFetch: true
}
}

export default defineConfig({
build: {
cssMinify: process.env.NODE_ENV === 'production',
Expand All @@ -20,6 +26,7 @@ export default defineConfig({
v3_relativeSplatPath: true,
v3_lazyRouteDiscovery: true,
v3_throwAbortReason: true,
v3_singleFetch: true,
},
serverModuleFormat: 'esm',
}),
Expand Down

0 comments on commit d7a09bd

Please sign in to comment.