Skip to content

Commit efb1e59

Browse files
Improve stylesheet loading` (#202)
* Refactor DocsLayout: Remove unused clientLoader and update stylesheet link precedence * Update stylesheet imports in root and docsearch components for improved loading
1 parent 7e05b09 commit efb1e59

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

app/modules/docsearch.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
} from "@docsearch/react";
1717
import type { HeaderData } from "~/components/docs-header/data.server";
1818

19+
import docsearchCss from "~/styles/docsearch.css?url";
20+
1921
let docSearchProps = {
2022
appId: "RB6LOUCOL0",
2123
indexName: "reactrouter",
@@ -71,6 +73,7 @@ export function DocSearch({ children }: { children: React.ReactNode }) {
7173

7274
return (
7375
<DocSearchContext value={contextValue}>
76+
<link rel="stylesheet" href={docsearchCss} precedence="high" />
7477
{children}
7578
{isOpen
7679
? createPortal(

app/pages/docs-layout.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { preload } from "react-dom";
21
import { Outlet, redirect } from "react-router";
32
import classNames from "classnames";
43

@@ -77,11 +76,6 @@ export async function loader({ request, params, context }: Route.LoaderArgs) {
7776
};
7877
}
7978

80-
export async function clientLoader({ serverLoader }: Route.ClientLoaderArgs) {
81-
preload(docsCss, { as: "style" });
82-
return await serverLoader();
83-
}
84-
8579
export default function DocsLayout({ loaderData }: Route.ComponentProps) {
8680
const { menu, header } = loaderData;
8781

@@ -96,7 +90,7 @@ export default function DocsLayout({ loaderData }: Route.ComponentProps) {
9690

9791
return (
9892
<>
99-
<link rel="stylesheet" href={docsCss} />
93+
<link rel="stylesheet" href={docsCss} precedence="high" />
10094
<div className="[--header-height:theme(spacing.16)] [--nav-width:theme(spacing.72)] lg:m-auto lg:max-w-[90rem]">
10195
<div className="sticky top-0 z-20">
10296
<Header />

app/root.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import { isHost } from "./modules/http-utils/is-host";
1818
import iconsHref from "~/icons.svg";
1919
import { DocSearch } from "./modules/docsearch";
2020

21-
import "~/styles/tailwind.css";
22-
import "@docsearch/css/dist/style.css";
23-
import "~/styles/docsearch.css";
21+
import tailwindCss from "~/styles/tailwind.css?url";
2422
import type { Route } from "./+types/root";
2523

2624
import { ensureSecure } from "~/modules/http-utils/ensure-secure";
@@ -77,6 +75,7 @@ export function Layout({ children }: { children: React.ReactNode }) {
7775
type="image/png"
7876
media="(prefers-color-scheme: dark)"
7977
/>
78+
<link rel="stylesheet" href={tailwindCss} precedence="high" />
8079
<Meta />
8180
<Links />
8281
</head>

app/styles/docsearch.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import "@docsearch/css/dist/style.css";
2+
13
/* this was copy/paste/modified from @docsearch/css/dist/_variables.css */
24
:root {
35
&:where(.dark) {

0 commit comments

Comments
 (0)