Skip to content

Commit 2e63c98

Browse files
committed
refactor: eager import to avoid async render blocks
1 parent 537ed00 commit 2e63c98

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

runtime/route.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const pages = import.meta.glob("#{__PLUGIN_PAGES_ROOT}");
1+
const pages = import.meta.glob("#{__PLUGIN_PAGES_ROOT}",{eager: false});
22

33
export const routes = normalizeRouteImports(pages, [
44
new RegExp("#{__PLUGIN_PAGES_ROOT_REGEX}"),

src/content/data.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1-
import { lazy } from "preact-iso";
1+
const contentMap = {};
2+
const posts = import.meta.glob("./**/*.mdx", { eager: true });
3+
for (let i in posts) {
4+
contentMap[i] = "default" in posts[i] ? posts[i].default : posts[i];
5+
}
26

37
export const sideBar = {
48
introduction: {
59
order: 1,
610
label: "Introduction",
7-
source: lazy(() => import("./introduction.mdx")),
11+
source: contentMap["./introduction.mdx"],
812
key: "introduction",
913
},
1014
essentials: {
1115
order: 2,
1216
label: "Essentials",
13-
source: lazy(() => import("./essentials.mdx")),
17+
source: contentMap["./essentials.mdx"],
1418
key: "essentials",
1519
},
1620
aesthetics: {
1721
order: 3,
1822
label: "Aesthetics",
19-
source: lazy(() => import("./aesthetics.mdx")),
23+
source: contentMap["./aesthetics.mdx"],
2024
key: "aesthetics",
2125
},
2226
"developer-experience": {
2327
order: 4,
2428
label: "Developer Experience",
25-
source: lazy(() => import("./developer-experience.mdx")),
29+
source: contentMap["./developer-experience.mdx"],
2630
key: "developer-experience",
2731
},
2832
frameworks: {
2933
order: 5,
3034
label: "Frameworks",
31-
source: lazy(() => import("./frameworks.mdx")),
35+
source: contentMap["./frameworks.mdx"],
3236
key: "frameworks",
3337
},
3438
templates: {
3539
order: 6,
3640
label: "Templates",
37-
source: lazy(() => import("./templates.mdx")),
41+
source: contentMap["./templates.mdx"],
3842
key: "templates",
3943
},
4044
};

src/main.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { hydrate, render } from "preact";
1+
import { render } from "preact";
22
import {
33
ErrorBoundary,
44
LocationProvider,
55
Route,
66
Router,
77
lazy,
88
prerender as ssr,
9+
hydrate,
910
} from "preact-iso";
1011
import { routes } from "~routes";
1112
import "./index.css";

src/pages/index.jsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { lazy } from "preact-iso";
21
import { sideBar } from "../content/data";
32
import BaseLayout from "../layouts/base";
4-
import { Suspense } from "preact/compat";
53

6-
const AllContent = () =>
7-
Object.keys(sideBar).map((d, i) => {
4+
const AllContent = () => {
5+
const components = [];
6+
let i = -1;
7+
for (let d in sideBar) {
8+
i++;
89
const Component = sideBar[d].source;
910
const classList = i > 0 ? "mt-12 pt-12" : "";
10-
return (
11-
<Suspense fallback={<div>Loading...</div>}>
12-
<Component class={classList} />
13-
</Suspense>
14-
);
15-
});
11+
components.push(<Component class={classList} />);
12+
}
13+
14+
return components;
15+
};
1616

1717
export default function HomePage() {
1818
return (

0 commit comments

Comments
 (0)