@heyo-sh/create-heyo-docs 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyo-sh/create-heyo-docs",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Create a standalone Heyo Docs documentation project.",
5
5
  "homepage": "https://heyo.sh",
6
6
  "repository": {
@@ -10,6 +10,7 @@ export const GET: APIRoute = ({ request }) => {
10
10
  "User-agent: *",
11
11
  "Allow: /",
12
12
  "Disallow: /__heyo-docs/",
13
+ "Disallow: /heyo-docs-internal/",
13
14
  "",
14
15
  `Sitemap: ${siteUrl}/sitemap.xml`,
15
16
  "",
@@ -7,6 +7,7 @@ export function GET(request: Request) {
7
7
  "User-agent: *",
8
8
  "Allow: /",
9
9
  "Disallow: /__heyo-docs/",
10
+ "Disallow: /heyo-docs-internal/",
10
11
  "",
11
12
  `Sitemap: ${siteUrl}/sitemap.xml`,
12
13
  "",
@@ -5,10 +5,7 @@ import {
5
5
  findOpenApiEndpoint,
6
6
  } from "@heyo-sh/heyo-docs/model";
7
7
  import { changelogGroupForPage } from "@heyo-sh/heyo-docs/navigation";
8
- import {
9
- openApiEndpointDataPath,
10
- openApiEndpointDetail,
11
- } from "@heyo-sh/heyo-docs/openapi";
8
+ import { openApiEndpointDetail } from "@heyo-sh/heyo-docs/openapi";
12
9
  import { docsSeoMeta } from "@heyo-sh/heyo-docs/seo/react-router";
13
10
  import type { OpenApiEndpoint } from "@heyo-sh/heyo-docs/types";
14
11
  import { useDocsTheme } from "@heyo-sh/heyo-docs/theme/provider";
@@ -16,6 +13,7 @@ import {
16
13
  Link,
17
14
  useLoaderData,
18
15
  useParams,
16
+ type ClientLoaderFunctionArgs,
19
17
  type LoaderFunctionArgs,
20
18
  type MetaFunction,
21
19
  } from "react-router";
@@ -48,33 +46,38 @@ export async function loader({ params }: LoaderFunctionArgs) {
48
46
 
49
47
  if (!endpoint) return {};
50
48
 
51
- // Prerendering serialises this operation-specific data with its static route,
52
- // so the browser's first paint already contains the complete API reference.
53
- if (typeof window === "undefined") {
54
- const serverModel = createDocsModel(config, pages, openApiDocuments);
55
- const currentOpenApiEndpoint = findOpenApiEndpoint(
56
- serverModel.endpoints,
57
- pathname,
58
- );
59
- return {
60
- currentOpenApiEndpoint: currentOpenApiEndpoint
61
- ? openApiEndpointDetail(currentOpenApiEndpoint)
62
- : undefined,
63
- };
64
- }
65
-
66
- // Client transitions wait for the static shard before committing the new
67
- // route. This prevents rendering the compact index and replacing it later.
68
- const response = await fetch(openApiEndpointDataPath(endpoint.slug));
69
- if (!response.ok)
70
- throw new Response("OpenAPI endpoint data could not be loaded", {
71
- status: response.status,
72
- });
49
+ // This loader runs on the server, including during prerendering, so the
50
+ // operation's full data is serialised with the route. First paint and every
51
+ // client transition therefore start from the complete API reference.
52
+ const serverModel = createDocsModel(config, pages, openApiDocuments);
53
+ const currentOpenApiEndpoint = findOpenApiEndpoint(
54
+ serverModel.endpoints,
55
+ pathname,
56
+ );
73
57
  return {
74
- currentOpenApiEndpoint: (await response.json()) as OpenApiEndpoint,
58
+ currentOpenApiEndpoint: currentOpenApiEndpoint
59
+ ? (openApiEndpointDetail(currentOpenApiEndpoint) as OpenApiEndpoint)
60
+ : undefined,
75
61
  };
76
62
  }
77
63
 
64
+ /**
65
+ * Loads the page's MDX chunk before the new route is displayed, so a reader
66
+ * never sees a loading placeholder replace the page they came from.
67
+ */
68
+ export async function clientLoader({
69
+ params,
70
+ serverLoader,
71
+ }: ClientLoaderFunctionArgs) {
72
+ const model = createDocsModel(config, pages, [], openApiEndpoints);
73
+ const page = findDocsPage(model.pages, pathnameFor(params));
74
+ const [data] = await Promise.all([
75
+ serverLoader<Awaited<ReturnType<typeof loader>>>(),
76
+ page?.preload?.(),
77
+ ]);
78
+ return data;
79
+ }
80
+
78
81
  export const meta: MetaFunction = ({ params }) => {
79
82
  const model = createDocsModel(config, pages, [], openApiEndpoints);
80
83
  const pathname = pathnameFor(params);
@@ -1 +1 @@
1
- export { default, loader, meta, ErrorBoundary } from "./docs";
1
+ export { default, clientLoader, loader, meta, ErrorBoundary } from "./docs";
@@ -10,6 +10,7 @@ export function loader({ request }: Route.LoaderArgs) {
10
10
  "User-agent: *",
11
11
  "Allow: /",
12
12
  "Disallow: /__heyo-docs/",
13
+ "Disallow: /heyo-docs-internal/",
13
14
  "",
14
15
  `Sitemap: ${siteUrl}/sitemap.xml`,
15
16
  "",