@@ -20,6 +20,7 @@ use std::pin::Pin;
20
20
use std:: sync:: Arc ;
21
21
use std:: { collections:: HashMap , rc:: Rc } ;
22
22
use sycamore:: prelude:: Scope ;
23
+ use sycamore:: utils:: hydrate:: with_no_hydration_context;
23
24
use sycamore:: {
24
25
prelude:: { component, view} ,
25
26
view:: View ,
@@ -527,20 +528,11 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
527
528
// The lifetime of the provided function doesn't need to be static, because we
528
529
// render using it and then we're done with it
529
530
pub fn index_view < ' a > ( mut self , f : impl Fn ( Scope ) -> View < SsrNode > + ' a ) -> Self {
530
- // This, very problematically, could add hydration IDs to the `<head>` and
531
- // `<body>`, which we MUST NOT have (or the HTML shell's interpolation breaks in
532
- // unexpected ways)
533
- let html_str = sycamore:: render_to_string ( f) ;
534
- // So, we get rid of the hydration IDs completely
535
- // We have to get rid of leftover spaces as well to make sure we're completely
536
- // good for the naive string replacement
537
- #[ cfg( not( target_arch = "wasm32" ) ) ]
538
- let html_str = regex:: Regex :: new ( r#"data-hk=".*?""# )
539
- . unwrap ( )
540
- . replace_all ( & html_str, "" )
541
- . to_string ( )
542
- . replace ( " >" , ">" ) ;
531
+ // We need to render the index view without any hydration IDs (which would break
532
+ // the HTML shell's interpolation mechanisms)
533
+ let html_str = sycamore:: render_to_string ( |cx| with_no_hydration_context ( || f ( cx) ) ) ;
543
534
self . index_view = html_str;
535
+
544
536
self
545
537
}
546
538
// Setters
@@ -859,7 +851,9 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> PerseusAppBase<G, M, T> {
859
851
#[ allow( non_snake_case) ]
860
852
pub fn PerseusRoot < G : Html > ( cx : Scope ) -> View < G > {
861
853
view ! { cx,
862
- div( dangerously_set_inner_html = "<div id=\" root\" ></div>" )
854
+ // Since we render the index view with no hydration IDs, this conforms
855
+ // to the expectations of the HTML shell
856
+ div( id = "root" )
863
857
}
864
858
}
865
859
0 commit comments