Skip to content

Commit 5938905

Browse files
committed
fix code editor with ssg rendering
1 parent 0e1d9b9 commit 5938905

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

docsite/src/main.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ fn App() -> Element {
211211
}
212212
}
213213

214+
/// Force the children to only render on the client
215+
#[component]
216+
fn ClientOnly(children: Element) -> Element {
217+
let mut on_client = use_signal(|| false);
218+
219+
use_effect(move || on_client.set(true));
220+
221+
if on_client() {
222+
children
223+
} else {
224+
rsx! {}
225+
}
226+
}
227+
214228
#[derive(Routable, Clone, PartialEq)]
215229
enum Route {
216230
#[route("/")]
@@ -715,13 +729,15 @@ fn Playground(
715729
}
716730
}
717731
}
718-
CodeEditor {
719-
value: source(),
720-
language: Language::Rust,
721-
theme,
722-
aria_label: "Rust source editor",
723-
class: "playground-code-editor",
724-
oninput: move |value| source.set(value),
732+
ClientOnly {
733+
CodeEditor {
734+
value: source(),
735+
language: Language::Rust,
736+
theme,
737+
aria_label: "Rust source editor",
738+
class: "playground-code-editor",
739+
oninput: move |value| source.set(value),
740+
}
725741
}
726742
}
727743
}

0 commit comments

Comments
 (0)