Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Reduce bundle size #906

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/ui/layout/hero-code-snippet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import { cache, createAsync } from "@solidjs/router";
import { codeToHtml } from "shiki";
import { createResource } from "solid-js";

export const counterTxt = `import { createSignal } from "solid-js";

Expand All @@ -17,16 +18,17 @@ function Counter() {

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

const renderCode = async () => {
const renderCode = cache(async () => {
"use server";
const code = counterTxt.trim();
return codeToHtml(code, {
lang: "tsx",
theme: "material-theme-ocean",
});
};
}, "render-code");

export default function CodeSnippet() {
const [code] = createResource(renderCode);
const code = createAsync(() => renderCode());

// eslint-disable-next-line solid/no-innerhtml
return <div innerHTML={code()} />;
Expand Down
12 changes: 4 additions & 8 deletions src/ui/layout/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import {
createMemo,
} from "solid-js";
import { ButtonLink } from "../button-link";
import { clientOnly } from "@solidjs/start";
import { counterTxt, snippetLines } from "./hero-code-snippet";
import CodeSnippet, { counterTxt, snippetLines } from "./hero-code-snippet";
import { useLocation, useMatch } from "@solidjs/router";
import { useI18n } from "~/i18n/i18n-context";

const RenderedCode = clientOnly(() => import("./hero-code-snippet"));

const TrafficLightsIcon: Component<{ class: string }> = (props) => {
return (
<svg aria-hidden="true" viewBox="0 0 42 10" fill="none" {...props}>
Expand Down Expand Up @@ -109,16 +106,15 @@ export const Hero: Component = () => {
</Index>
</div>
<div
class={`flex overflow-x-auto px-4 min-h-[${
snippetLines.length + 5
}em] text-white custom-scrollbar`}
class={`flex overflow-x-auto px-4 min-h-[${snippetLines.length + 5
}em] text-white custom-scrollbar`}
>
<Suspense
fallback={
<pre class="text-slate-300">{counterTxt}</pre>
}
>
<RenderedCode />
<CodeSnippet />
</Suspense>
</div>
</div>
Expand Down