update
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
import type { Route } from './+types'
|
import type { Route } from './+types'
|
||||||
|
|
||||||
|
import { isValidCPF } from '@brazilian-utils/brazilian-utils'
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod'
|
||||||
|
import { Loader2Icon } from 'lucide-react'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { useForm } from 'react-hook-form'
|
||||||
|
import { Link, useFetcher } from 'react-router'
|
||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
import logo from '@/components/logo.svg'
|
import logo from '@/components/logo.svg'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Checkbox } from '@/components/ui/checkbox'
|
import { Checkbox } from '@/components/ui/checkbox'
|
||||||
@@ -13,13 +21,6 @@ import {
|
|||||||
} from '@/components/ui/form'
|
} from '@/components/ui/form'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { isValidCPF } from '@brazilian-utils/brazilian-utils'
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod'
|
|
||||||
import { Loader2Icon } from 'lucide-react'
|
|
||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { useForm } from 'react-hook-form'
|
|
||||||
import { Link, useFetcher } from 'react-router'
|
|
||||||
import { z } from 'zod'
|
|
||||||
import { FOUND, INTERNAL_SERVER_ERROR, OK } from './authorize'
|
import { FOUND, INTERNAL_SERVER_ERROR, OK } from './authorize'
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { AppLoadContext, EntryContext } from "react-router";
|
import { isbot } from 'isbot'
|
||||||
import { ServerRouter } from "react-router";
|
import { renderToReadableStream } from 'react-dom/server'
|
||||||
import { isbot } from "isbot";
|
import type { AppLoadContext, EntryContext } from 'react-router'
|
||||||
import { renderToReadableStream } from "react-dom/server";
|
import { ServerRouter } from 'react-router'
|
||||||
|
|
||||||
export default async function handleRequest(
|
export default async function handleRequest(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -10,34 +10,34 @@ export default async function handleRequest(
|
|||||||
routerContext: EntryContext,
|
routerContext: EntryContext,
|
||||||
_loadContext: AppLoadContext
|
_loadContext: AppLoadContext
|
||||||
) {
|
) {
|
||||||
let shellRendered = false;
|
let shellRendered = false
|
||||||
const userAgent = request.headers.get("user-agent");
|
const userAgent = request.headers.get('user-agent')
|
||||||
|
|
||||||
const body = await renderToReadableStream(
|
const body = await renderToReadableStream(
|
||||||
<ServerRouter context={routerContext} url={request.url} />,
|
<ServerRouter context={routerContext} url={request.url} />,
|
||||||
{
|
{
|
||||||
onError(error: unknown) {
|
onError(error: unknown) {
|
||||||
responseStatusCode = 500;
|
responseStatusCode = 500
|
||||||
// Log streaming rendering errors from inside the shell. Don't log
|
// Log streaming rendering errors from inside the shell. Don't log
|
||||||
// errors encountered during initial shell rendering since they'll
|
// errors encountered during initial shell rendering since they'll
|
||||||
// reject and get logged in handleDocumentRequest.
|
// reject and get logged in handleDocumentRequest.
|
||||||
if (shellRendered) {
|
if (shellRendered) {
|
||||||
console.error(error);
|
console.error(error)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
shellRendered = true;
|
shellRendered = true
|
||||||
|
|
||||||
// Ensure requests from bots and SPA Mode renders wait for all content to load before responding
|
// Ensure requests from bots and SPA Mode renders wait for all content to load before responding
|
||||||
// https://react.dev/reference/react-dom/server/renderToPipeableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation
|
// https://react.dev/reference/react-dom/server/renderToPipeableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation
|
||||||
if ((userAgent && isbot(userAgent)) || routerContext.isSpaMode) {
|
if ((userAgent && isbot(userAgent)) || routerContext.isSpaMode) {
|
||||||
await body.allReady;
|
await body.allReady
|
||||||
}
|
}
|
||||||
|
|
||||||
responseHeaders.set("Content-Type", "text/html");
|
responseHeaders.set('Content-Type', 'text/html')
|
||||||
return new Response(body, {
|
return new Response(body, {
|
||||||
headers: responseHeaders,
|
headers: responseHeaders,
|
||||||
status: responseStatusCode,
|
status: responseStatusCode
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,24 +4,24 @@ import {
|
|||||||
Meta,
|
Meta,
|
||||||
Outlet,
|
Outlet,
|
||||||
Scripts,
|
Scripts,
|
||||||
ScrollRestoration,
|
ScrollRestoration
|
||||||
} from "react-router";
|
} from 'react-router'
|
||||||
|
|
||||||
import type { Route } from "./+types/root";
|
import type { Route } from './+types/root'
|
||||||
import "./app.css";
|
import './app.css'
|
||||||
|
|
||||||
export const links: Route.LinksFunction = () => [
|
export const links: Route.LinksFunction = () => [
|
||||||
{ rel: "preconnect", href: "https://fonts.googleapis.com" },
|
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
|
||||||
{
|
{
|
||||||
rel: "preconnect",
|
rel: 'preconnect',
|
||||||
href: "https://fonts.gstatic.com",
|
href: 'https://fonts.gstatic.com',
|
||||||
crossOrigin: "anonymous",
|
crossOrigin: 'anonymous'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rel: "stylesheet",
|
rel: 'stylesheet',
|
||||||
href: "https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap",
|
href: 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap'
|
||||||
},
|
}
|
||||||
];
|
]
|
||||||
|
|
||||||
export function Layout({ children }: { children: React.ReactNode }) {
|
export function Layout({ children }: { children: React.ReactNode }) {
|
||||||
return (
|
return (
|
||||||
@@ -38,27 +38,27 @@ export function Layout({ children }: { children: React.ReactNode }) {
|
|||||||
<Scripts />
|
<Scripts />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
return <Outlet />;
|
return <Outlet />
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
||||||
let message = "Oops!";
|
let message = 'Oops!'
|
||||||
let details = "An unexpected error occurred.";
|
let details = 'An unexpected error occurred.'
|
||||||
let stack: string | undefined;
|
let stack: string | undefined
|
||||||
|
|
||||||
if (isRouteErrorResponse(error)) {
|
if (isRouteErrorResponse(error)) {
|
||||||
message = error.status === 404 ? "404" : "Error";
|
message = error.status === 404 ? '404' : 'Error'
|
||||||
details =
|
details =
|
||||||
error.status === 404
|
error.status === 404
|
||||||
? "The requested page could not be found."
|
? 'The requested page could not be found.'
|
||||||
: error.statusText || details;
|
: error.statusText || details
|
||||||
} else if (import.meta.env.DEV && error && error instanceof Error) {
|
} else if (import.meta.env.DEV && error && error instanceof Error) {
|
||||||
details = error.message;
|
details = error.message
|
||||||
stack = error.stack;
|
stack = error.stack
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -71,5 +71,5 @@ export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
|||||||
</pre>
|
</pre>
|
||||||
)}
|
)}
|
||||||
</main>
|
</main>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
import { type RouteConfig, index } from "@react-router/dev/routes";
|
import { index, type RouteConfig } from '@react-router/dev/routes'
|
||||||
|
|
||||||
export default [index("routes/home.tsx")] satisfies RouteConfig;
|
export default [index('routes/home.tsx')] satisfies RouteConfig
|
||||||
|
|||||||
Reference in New Issue
Block a user