Skip to content

Commit 78e2aea

Browse files
Reduce bundle size (#906)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 89a1883 commit 78e2aea

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/ui/layout/hero-code-snippet.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
2+
import { cache, createAsync } from "@solidjs/router";
13
import { codeToHtml } from "shiki";
2-
import { createResource } from "solid-js";
34

45
export const counterTxt = `import { createSignal } from "solid-js";
56
@@ -17,16 +18,17 @@ function Counter() {
1718

1819
export const snippetLines = counterTxt.split("\n");
1920

20-
const renderCode = async () => {
21+
const renderCode = cache(async () => {
22+
"use server";
2123
const code = counterTxt.trim();
2224
return codeToHtml(code, {
2325
lang: "tsx",
2426
theme: "material-theme-ocean",
2527
});
26-
};
28+
}, "render-code");
2729

2830
export default function CodeSnippet() {
29-
const [code] = createResource(renderCode);
31+
const code = createAsync(() => renderCode());
3032

3133
// eslint-disable-next-line solid/no-innerhtml
3234
return <div innerHTML={code()} />;

src/ui/layout/hero.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ import {
77
createMemo,
88
} from "solid-js";
99
import { ButtonLink } from "../button-link";
10-
import { clientOnly } from "@solidjs/start";
11-
import { counterTxt, snippetLines } from "./hero-code-snippet";
10+
import CodeSnippet, { counterTxt, snippetLines } from "./hero-code-snippet";
1211
import { useLocation, useMatch } from "@solidjs/router";
1312
import { useI18n } from "~/i18n/i18n-context";
1413

15-
const RenderedCode = clientOnly(() => import("./hero-code-snippet"));
16-
1714
const TrafficLightsIcon: Component<{ class: string }> = (props) => {
1815
return (
1916
<svg aria-hidden="true" viewBox="0 0 42 10" fill="none" {...props}>
@@ -109,16 +106,15 @@ export const Hero: Component = () => {
109106
</Index>
110107
</div>
111108
<div
112-
class={`flex overflow-x-auto px-4 min-h-[${
113-
snippetLines.length + 5
114-
}em] text-white custom-scrollbar`}
109+
class={`flex overflow-x-auto px-4 min-h-[${snippetLines.length + 5
110+
}em] text-white custom-scrollbar`}
115111
>
116112
<Suspense
117113
fallback={
118114
<pre class="text-slate-300">{counterTxt}</pre>
119115
}
120116
>
121-
<RenderedCode />
117+
<CodeSnippet />
122118
</Suspense>
123119
</div>
124120
</div>

0 commit comments

Comments
 (0)