File tree Expand file tree Collapse file tree 2 files changed +10
-12
lines changed
Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change 1+
2+ import { cache , createAsync } from "@solidjs/router" ;
13import { codeToHtml } from "shiki" ;
2- import { createResource } from "solid-js" ;
34
45export const counterTxt = `import { createSignal } from "solid-js";
56
@@ -17,16 +18,17 @@ function Counter() {
1718
1819export 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
2830export 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 ( ) } /> ;
Original file line number Diff line number Diff line change @@ -7,13 +7,10 @@ import {
77 createMemo ,
88} from "solid-js" ;
99import { 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" ;
1211import { useLocation , useMatch } from "@solidjs/router" ;
1312import { useI18n } from "~/i18n/i18n-context" ;
1413
15- const RenderedCode = clientOnly ( ( ) => import ( "./hero-code-snippet" ) ) ;
16-
1714const 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 >
You can’t perform that action at this time.
0 commit comments