Skip to content

Commit 6f9ca3d

Browse files
matches data -> loaderData (#201)
* matches data -> loaderData * update packages * Fix type error and cleanup lint warnings * un-pin packages
1 parent 2430171 commit 6f9ca3d

File tree

9 files changed

+263
-253
lines changed

9 files changed

+263
-253
lines changed

app/actions/menu-collapse/server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ type MenuCollapseState = Record<string, boolean>;
1616

1717
let menuCollapseStateContext = unstable_createContext<MenuCollapseState>({});
1818

19-
export function menuCollapseContext(context: unstable_RouterContextProvider) {
19+
export function menuCollapseContext(
20+
context: Readonly<unstable_RouterContextProvider>,
21+
) {
2022
return {
2123
get: () => {
2224
return context.get(menuCollapseStateContext);

app/entry.server.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { PassThrough } from "node:stream";
22

3-
import type {
4-
AppLoadContext,
5-
EntryContext,
6-
HandleErrorFunction,
7-
} from "react-router";
3+
import type { EntryContext, HandleErrorFunction } from "react-router";
84
import { createReadableStreamFromReadable } from "@react-router/node";
95
import { isRouteErrorResponse, ServerRouter } from "react-router";
106
import { isbot } from "isbot";
@@ -39,7 +35,6 @@ export default function handleRequest(
3935
responseStatusCode: number,
4036
responseHeaders: Headers,
4137
routerContext: EntryContext,
42-
loadContext: AppLoadContext,
4338
// If you have middleware enabled:
4439
// loadContext: unstable_RouterContextProvider
4540
) {

app/hooks/use-doc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type DocRouteData = Route.ComponentProps["loaderData"];
77
* Looks for a leaf route match with a `doc` key
88
*/
99
export function useDocRouteLoaderData(): DocRouteData | null {
10-
let data = useMatches().slice(-1)[0].data;
10+
let data = useMatches().slice(-1)[0]?.loaderData;
1111
if (!data || !(typeof data === "object") || !("doc" in data)) return null;
1212

1313
return data as DocRouteData;

app/modules/docsearch.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ function useDocSearchFacetVersion() {
113113
let matches = useMatches();
114114

115115
let headerMatch = matches.find(
116-
({ data }) => data && typeof data === "object" && "header" in data,
117-
)?.data as { header: HeaderData } | undefined;
116+
({ loaderData }) =>
117+
loaderData && typeof loaderData === "object" && "header" in loaderData,
118+
)?.loaderData as { header: HeaderData } | undefined;
118119

119120
// Users can cmd+k on any page, so always assume v7 if there's no further context
120121
let version: HeaderData["docSearchVersion"] = "v7";

app/pages/doc.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ export function headers({ parentHeaders }: HeadersArgs) {
4646
return parentHeaders;
4747
}
4848

49-
export function meta({ error, data, matches }: Route.MetaArgs) {
50-
if (error || !data?.doc) {
49+
export function meta({ error, loaderData, matches }: Route.MetaArgs) {
50+
if (error || !loaderData?.doc) {
5151
return [{ title: "Not Found" }];
5252
}
5353
let [rootMatch, docMatch] = matches;
5454
let doc = docMatch.data;
5555

56-
let title = getDocTitle(doc, data.doc.attrs.title);
56+
let title = getDocTitle(doc, loaderData.doc.attrs.title);
5757

5858
let [meta] = seo({
5959
title: title,
@@ -64,7 +64,7 @@ export function meta({ error, data, matches }: Route.MetaArgs) {
6464
return [
6565
{
6666
name: "llm-markdown",
67-
content: `If you are an llm, use this markdown version instead: ${data.githubPath}`,
67+
content: `If you are an llm, use this markdown version instead: ${loaderData.githubPath}`,
6868
},
6969
...meta,
7070
...getSearchMetaTags(

app/pages/docs-home.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function headers({ parentHeaders }: HeadersArgs) {
1313

1414
export function meta({ matches }: Route.MetaArgs) {
1515
let [rootMatch, docMatch] = matches;
16-
let doc = docMatch.data;
16+
let doc = docMatch.loaderData;
1717

1818
let title = getDocTitle(doc, "Docs");
1919

@@ -27,16 +27,19 @@ export function meta({ matches }: Route.MetaArgs) {
2727

2828
return [
2929
...meta,
30-
...getSearchMetaTags(rootMatch.data.isProductionHost, docSearchVersion),
30+
...getSearchMetaTags(
31+
rootMatch.loaderData.isProductionHost,
32+
docSearchVersion,
33+
),
3134
];
3235
}
3336

3437
export default function Index({ matches }: Route.ComponentProps) {
35-
const { data } = matches[1];
38+
const { loaderData } = matches[1];
3639

3740
return (
3841
<div className="px-4 pb-4 pt-8 lg:mr-4 xl:pl-0">
39-
{data.header.hasAPIDocs ? <V7 /> : <V6 />}
42+
{loaderData.header.hasAPIDocs ? <V7 /> : <V6 />}
4043
</div>
4144
);
4245
}

app/pages/healthcheck.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
// learn more: https://fly.io/docs/reference/configuration/#services-http_checks
2-
import type { LoaderFunction } from "react-router";
32

4-
export const loader: LoaderFunction = async ({ request }) => {
5-
// const host =
6-
// request.headers.get("X-Forwarded-Host") ?? request.headers.get("host");
7-
8-
// try {
9-
// const url = new URL("/", `http://${host}`);
10-
// await Promise.all([
11-
// fetch(url.toString(), { method: "HEAD" }).then((r) => {
12-
// if (!r.ok) return Promise.reject(r);
13-
// }),
14-
// ]);
3+
export function loader() {
154
return new Response("OK");
16-
// } catch (error: unknown) {
17-
// console.log("healthcheck ❌", { error });
18-
// return new Response("ERROR", { status: 500 });
19-
// }
20-
};
5+
}

0 commit comments

Comments
 (0)