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" ;
1
3
import { codeToHtml } from "shiki" ;
2
- import { createResource } from "solid-js" ;
3
4
4
5
export const counterTxt = `import { createSignal } from "solid-js";
5
6
@@ -17,16 +18,17 @@ function Counter() {
17
18
18
19
export const snippetLines = counterTxt . split ( "\n" ) ;
19
20
20
- const renderCode = async ( ) => {
21
+ const renderCode = cache ( async ( ) => {
22
+ "use server" ;
21
23
const code = counterTxt . trim ( ) ;
22
24
return codeToHtml ( code , {
23
25
lang : "tsx" ,
24
26
theme : "material-theme-ocean" ,
25
27
} ) ;
26
- } ;
28
+ } , "render-code" ) ;
27
29
28
30
export default function CodeSnippet ( ) {
29
- const [ code ] = createResource ( renderCode ) ;
31
+ const code = createAsync ( ( ) => renderCode ( ) ) ;
30
32
31
33
// eslint-disable-next-line solid/no-innerhtml
32
34
return < div innerHTML = { code ( ) } /> ;
Original file line number Diff line number Diff line change @@ -7,13 +7,10 @@ import {
7
7
createMemo ,
8
8
} from "solid-js" ;
9
9
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" ;
12
11
import { useLocation , useMatch } from "@solidjs/router" ;
13
12
import { useI18n } from "~/i18n/i18n-context" ;
14
13
15
- const RenderedCode = clientOnly ( ( ) => import ( "./hero-code-snippet" ) ) ;
16
-
17
14
const TrafficLightsIcon : Component < { class : string } > = ( props ) => {
18
15
return (
19
16
< svg aria-hidden = "true" viewBox = "0 0 42 10" fill = "none" { ...props } >
@@ -109,16 +106,15 @@ export const Hero: Component = () => {
109
106
</ Index >
110
107
</ div >
111
108
< 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`}
115
111
>
116
112
< Suspense
117
113
fallback = {
118
114
< pre class = "text-slate-300" > { counterTxt } </ pre >
119
115
}
120
116
>
121
- < RenderedCode />
117
+ < CodeSnippet />
122
118
</ Suspense >
123
119
</ div >
124
120
</ div >
You can’t perform that action at this time.
0 commit comments