Skip to content

Commit

Permalink
Replace DataFunctionArgs with LoaderFunctionArgs and ActionFunctionAr…
Browse files Browse the repository at this point in the history
…gs (#573) (#591)
  • Loading branch information
diegotc86 authored Jan 8, 2024
1 parent 56fd299 commit c845cd9
Show file tree
Hide file tree
Showing 42 changed files with 151 additions and 101 deletions.
8 changes: 4 additions & 4 deletions .vscode/remix.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"prefix": "/loader",
"scope": "typescriptreact,javascriptreact,typescript,javascript",
"body": [
"import { type DataFunctionArgs, json } from \"@remix-run/node\"",
"import { type LoaderFunctionArgs, json } from \"@remix-run/node\"",
"",
"export async function loader({ request }: DataFunctionArgs) {",
"export async function loader({ request }: LoaderFunctionArgs) {",
" return json({})",
"}"
]
Expand All @@ -14,9 +14,9 @@
"prefix": "/action",
"scope": "typescriptreact,javascriptreact,typescript,javascript",
"body": [
"import { type DataFunctionArgs, json } from \"@remix-run/node\"",
"import { type ActionFunctionArgs, json } from \"@remix-run/node\"",
"",
"export async function action({ request }: DataFunctionArgs) {",
"export async function action({ request }: ActionFunctionArgs) {",
" return json({})",
"}"
]
Expand Down
5 changes: 3 additions & 2 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PassThrough } from 'stream'
import {
createReadableStreamFromReadable,
type DataFunctionArgs,
type LoaderFunctionArgs,
type ActionFunctionArgs,
type HandleDocumentRequestFunction,
} from '@remix-run/node'
import { RemixServer } from '@remix-run/react'
Expand Down Expand Up @@ -94,7 +95,7 @@ export async function handleDataRequest(response: Response) {

export function handleError(
error: unknown,
{ request }: DataFunctionArgs,
{ request }: LoaderFunctionArgs | ActionFunctionArgs,
): void {
if (error instanceof Error) {
Sentry.captureRemixServerException(error, 'remix.server', request)
Expand Down
7 changes: 4 additions & 3 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { parse } from '@conform-to/zod'
import { cssBundleHref } from '@remix-run/css-bundle'
import {
json,
type DataFunctionArgs,
type LoaderFunctionArgs,
type ActionFunctionArgs,
type HeadersFunction,
type LinksFunction,
type MetaFunction,
Expand Down Expand Up @@ -91,7 +92,7 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
]
}

export async function loader({ request }: DataFunctionArgs) {
export async function loader({ request }: LoaderFunctionArgs) {
const timings = makeTimings('root loader')
const userId = await time(() => getUserId(request), {
timings,
Expand Down Expand Up @@ -169,7 +170,7 @@ const ThemeFormSchema = z.object({
theme: z.enum(['system', 'light', 'dark']),
})

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
const formData = await request.formData()
const submission = parse(formData, {
schema: ThemeFormSchema,
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_auth+/auth.$provider.callback.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { redirect, type DataFunctionArgs } from '@remix-run/node'
import { redirect, type LoaderFunctionArgs } from '@remix-run/node'
import {
authenticator,
getSessionExpirationDate,
Expand All @@ -25,7 +25,7 @@ import {

const destroyRedirectTo = { 'set-cookie': destroyRedirectToHeader }

export async function loader({ request, params }: DataFunctionArgs) {
export async function loader({ request, params }: LoaderFunctionArgs) {
const providerName = ProviderNameSchema.parse(params.provider)
const redirectTo = getRedirectCookieValue(request)
const label = providerLabels[providerName]
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_auth+/auth.$provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { redirect, type DataFunctionArgs } from '@remix-run/node'
import { redirect, type ActionFunctionArgs } from '@remix-run/node'
import { authenticator } from '#app/utils/auth.server.ts'
import { handleMockAction } from '#app/utils/connections.server.ts'
import { ProviderNameSchema } from '#app/utils/connections.tsx'
Expand All @@ -9,7 +9,7 @@ export async function loader() {
return redirect('/login')
}

export async function action({ request, params }: DataFunctionArgs) {
export async function action({ request, params }: ActionFunctionArgs) {
const providerName = ProviderNameSchema.parse(params.provider)

try {
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_auth+/forgot-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as E from '@react-email/components'
import {
json,
redirect,
type DataFunctionArgs,
type ActionFunctionArgs,
type MetaFunction,
} from '@remix-run/node'
import { Link, useFetcher } from '@remix-run/react'
Expand All @@ -25,7 +25,7 @@ const ForgotPasswordSchema = z.object({
usernameOrEmail: z.union([EmailSchema, UsernameSchema]),
})

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
const formData = await request.formData()
await validateCSRF(formData, request.headers)
checkHoneypot(formData)
Expand Down
7 changes: 4 additions & 3 deletions app/routes/_auth+/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { invariant } from '@epic-web/invariant'
import {
json,
redirect,
type DataFunctionArgs,
type LoaderFunctionArgs,
type ActionFunctionArgs,
type MetaFunction,
} from '@remix-run/node'
import { Form, Link, useActionData, useSearchParams } from '@remix-run/react'
Expand Down Expand Up @@ -188,12 +189,12 @@ const LoginFormSchema = z.object({
remember: z.boolean().optional(),
})

export async function loader({ request }: DataFunctionArgs) {
export async function loader({ request }: LoaderFunctionArgs) {
await requireAnonymous(request)
return json({})
}

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
await requireAnonymous(request)
const formData = await request.formData()
await validateCSRF(formData, request.headers)
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_auth+/logout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { redirect, type DataFunctionArgs } from '@remix-run/node'
import { redirect, type ActionFunctionArgs } from '@remix-run/node'
import { logout } from '#app/utils/auth.server.ts'

export async function loader() {
return redirect('/')
}

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
return logout({ request })
}
7 changes: 4 additions & 3 deletions app/routes/_auth+/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { invariant } from '@epic-web/invariant'
import {
json,
redirect,
type DataFunctionArgs,
type LoaderFunctionArgs,
type ActionFunctionArgs,
type MetaFunction,
} from '@remix-run/node'
import {
Expand Down Expand Up @@ -61,12 +62,12 @@ async function requireOnboardingEmail(request: Request) {
}
return email
}
export async function loader({ request }: DataFunctionArgs) {
export async function loader({ request }: LoaderFunctionArgs) {
const email = await requireOnboardingEmail(request)
return json({ email })
}

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
const email = await requireOnboardingEmail(request)
const formData = await request.formData()
await validateCSRF(formData, request.headers)
Expand Down
7 changes: 4 additions & 3 deletions app/routes/_auth+/onboarding_.$provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { invariant } from '@epic-web/invariant'
import {
json,
redirect,
type DataFunctionArgs,
type LoaderFunctionArgs,
type ActionFunctionArgs,
type MetaFunction,
} from '@remix-run/node'
import {
Expand Down Expand Up @@ -77,7 +78,7 @@ async function requireData({
}
}

export async function loader({ request, params }: DataFunctionArgs) {
export async function loader({ request, params }: LoaderFunctionArgs) {
const { email } = await requireData({ request, params })
const authSession = await authSessionStorage.getSession(
request.headers.get('cookie'),
Expand All @@ -102,7 +103,7 @@ export async function loader({ request, params }: DataFunctionArgs) {
})
}

export async function action({ request, params }: DataFunctionArgs) {
export async function action({ request, params }: ActionFunctionArgs) {
const { email, providerId, providerName } = await requireData({
request,
params,
Expand Down
7 changes: 4 additions & 3 deletions app/routes/_auth+/reset-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { invariant } from '@epic-web/invariant'
import {
json,
redirect,
type DataFunctionArgs,
type LoaderFunctionArgs,
type ActionFunctionArgs,
type MetaFunction,
} from '@remix-run/node'
import { Form, useActionData, useLoaderData } from '@remix-run/react'
Expand Down Expand Up @@ -59,12 +60,12 @@ async function requireResetPasswordUsername(request: Request) {
return resetPasswordUsername
}

export async function loader({ request }: DataFunctionArgs) {
export async function loader({ request }: LoaderFunctionArgs) {
const resetPasswordUsername = await requireResetPasswordUsername(request)
return json({ resetPasswordUsername })
}

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
const resetPasswordUsername = await requireResetPasswordUsername(request)
const formData = await request.formData()
const submission = parse(formData, {
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_auth+/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as E from '@react-email/components'
import {
json,
redirect,
type DataFunctionArgs,
type ActionFunctionArgs,
type MetaFunction,
} from '@remix-run/node'
import { Form, useActionData, useSearchParams } from '@remix-run/react'
Expand All @@ -30,7 +30,7 @@ const SignupSchema = z.object({
email: EmailSchema,
})

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
const formData = await request.formData()

await validateCSRF(formData, request.headers)
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_auth+/verify.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { conform, useForm, type Submission } from '@conform-to/react'
import { getFieldsetConstraint, parse } from '@conform-to/zod'
import { json, type DataFunctionArgs } from '@remix-run/node'
import { json, type ActionFunctionArgs } from '@remix-run/node'
import { Form, useActionData, useSearchParams } from '@remix-run/react'
import { AuthenticityTokenInput } from 'remix-utils/csrf/react'
import { HoneypotInputs } from 'remix-utils/honeypot/react'
Expand Down Expand Up @@ -42,7 +42,7 @@ const VerifySchema = z.object({
[redirectToQueryParam]: z.string().optional(),
})

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
const formData = await request.formData()
checkHoneypot(formData)
await validateCSRF(formData, request.headers)
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_seo+/robots[.]txt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { generateRobotsTxt } from '@nasa-gcn/remix-seo'
import { type DataFunctionArgs } from '@remix-run/node'
import { type LoaderFunctionArgs } from '@remix-run/node'
import { getDomainUrl } from '#app/utils/misc.tsx'

export function loader({ request }: DataFunctionArgs) {
export function loader({ request }: LoaderFunctionArgs) {
return generateRobotsTxt([
{ type: 'sitemap', value: `${getDomainUrl(request)}/sitemap.xml` },
])
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_seo+/sitemap[.]xml.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { generateSitemap } from '@nasa-gcn/remix-seo'
import { routes } from '@remix-run/dev/server-build'
import { type DataFunctionArgs } from '@remix-run/node'
import { type LoaderFunctionArgs } from '@remix-run/node'
import { getDomainUrl } from '#app/utils/misc.tsx'

export function loader({ request }: DataFunctionArgs) {
export function loader({ request }: LoaderFunctionArgs) {
return generateSitemap(request, routes, {
siteUrl: getDomainUrl(request),
headers: {
Expand Down
11 changes: 8 additions & 3 deletions app/routes/admin+/cache.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { invariantResponse } from '@epic-web/invariant'
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import { json, redirect, type DataFunctionArgs } from '@remix-run/node'
import {
json,
redirect,
type LoaderFunctionArgs,
type ActionFunctionArgs,
} from '@remix-run/node'
import {
Form,
Link,
Expand Down Expand Up @@ -30,7 +35,7 @@ export const handle: SEOHandle = {
getSitemapEntries: () => null,
}

export async function loader({ request }: DataFunctionArgs) {
export async function loader({ request }: LoaderFunctionArgs) {
await requireUserWithRole(request, 'admin')
const searchParams = new URL(request.url).searchParams
const query = searchParams.get('query')
Expand All @@ -55,7 +60,7 @@ export async function loader({ request }: DataFunctionArgs) {
return json({ cacheKeys, instance, instances, currentInstanceInfo })
}

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
await requireUserWithRole(request, 'admin')
const formData = await request.formData()
const key = formData.get('cacheKey')
Expand Down
4 changes: 2 additions & 2 deletions app/routes/admin+/cache_.lru.$cacheKey.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { invariantResponse } from '@epic-web/invariant'
import { json, type DataFunctionArgs } from '@remix-run/node'
import { json, type LoaderFunctionArgs } from '@remix-run/node'
import { getAllInstances, getInstanceInfo } from 'litefs-js'
import { ensureInstance } from 'litefs-js/remix.js'
import { lruCache } from '#app/utils/cache.server.ts'
import { requireUserWithRole } from '#app/utils/permissions.ts'

export async function loader({ request, params }: DataFunctionArgs) {
export async function loader({ request, params }: LoaderFunctionArgs) {
await requireUserWithRole(request, 'admin')
const searchParams = new URL(request.url).searchParams
const currentInstanceInfo = await getInstanceInfo()
Expand Down
4 changes: 2 additions & 2 deletions app/routes/admin+/cache_.sqlite.$cacheKey.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { invariantResponse } from '@epic-web/invariant'
import { json, type DataFunctionArgs } from '@remix-run/node'
import { json, type LoaderFunctionArgs } from '@remix-run/node'
import { getAllInstances, getInstanceInfo } from 'litefs-js'
import { ensureInstance } from 'litefs-js/remix.js'
import { cache } from '#app/utils/cache.server.ts'
import { requireUserWithRole } from '#app/utils/permissions.ts'

export async function loader({ request, params }: DataFunctionArgs) {
export async function loader({ request, params }: LoaderFunctionArgs) {
await requireUserWithRole(request, 'admin')
const searchParams = new URL(request.url).searchParams
const currentInstanceInfo = await getInstanceInfo()
Expand Down
4 changes: 2 additions & 2 deletions app/routes/admin+/cache_.sqlite.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type DataFunctionArgs, json, redirect } from '@remix-run/node'
import { type ActionFunctionArgs, json, redirect } from '@remix-run/node'
import { getInstanceInfo, getInternalInstanceDomain } from 'litefs-js'
import { z } from 'zod'
import { cache } from '#app/utils/cache.server.ts'

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
const { currentIsPrimary, primaryInstance } = await getInstanceInfo()
if (!currentIsPrimary) {
throw new Error(
Expand Down
4 changes: 2 additions & 2 deletions app/routes/me.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { redirect, type DataFunctionArgs } from '@remix-run/node'
import { redirect, type LoaderFunctionArgs } from '@remix-run/node'
import { requireUserId, logout } from '#app/utils/auth.server.ts'
import { prisma } from '#app/utils/db.server.ts'

export async function loader({ request }: DataFunctionArgs) {
export async function loader({ request }: LoaderFunctionArgs) {
const userId = await requireUserId(request)
const user = await prisma.user.findUnique({ where: { id: userId } })
if (!user) {
Expand Down
4 changes: 2 additions & 2 deletions app/routes/resources+/download-user-data.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { json, type DataFunctionArgs } from '@remix-run/node'
import { json, type LoaderFunctionArgs } from '@remix-run/node'
import { requireUserId } from '#app/utils/auth.server.ts'
import { prisma } from '#app/utils/db.server.ts'
import { getDomainUrl } from '#app/utils/misc.tsx'

export async function loader({ request }: DataFunctionArgs) {
export async function loader({ request }: LoaderFunctionArgs) {
const userId = await requireUserId(request)
const user = await prisma.user.findUniqueOrThrow({
where: { id: userId },
Expand Down
4 changes: 2 additions & 2 deletions app/routes/resources+/healthcheck.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// learn more: https://fly.io/docs/reference/configuration/#services-http_checks
import { type DataFunctionArgs } from '@remix-run/node'
import { type LoaderFunctionArgs } from '@remix-run/node'
import { prisma } from '#app/utils/db.server.ts'

export async function loader({ request }: DataFunctionArgs) {
export async function loader({ request }: LoaderFunctionArgs) {
const host =
request.headers.get('X-Forwarded-Host') ?? request.headers.get('host')

Expand Down
Loading

0 comments on commit c845cd9

Please sign in to comment.