@@ -15,7 +15,8 @@ use web_sys::{HtmlElement, HtmlTextAreaElement};
15
15
use yew:: platform:: time:: sleep;
16
16
use yew:: prelude:: * ;
17
17
use yew:: suspense:: { use_future, Suspension , SuspensionResult } ;
18
- use yew:: { Renderer , ServerRenderer } ;
18
+ use yew:: virtual_dom:: VNode ;
19
+ use yew:: { function_component, Renderer , ServerRenderer } ;
19
20
20
21
wasm_bindgen_test:: wasm_bindgen_test_configure!( run_in_browser) ;
21
22
@@ -94,6 +95,60 @@ async fn hydration_works() {
94
95
) ;
95
96
}
96
97
98
+ #[ wasm_bindgen_test]
99
+ async fn hydration_with_raw ( ) {
100
+ #[ function_component( Content ) ]
101
+ fn content ( ) -> Html {
102
+ let vnode = VNode :: from_html_unchecked ( "<div><p>Hello World</p></div>" . into ( ) ) ;
103
+
104
+ html ! {
105
+ <div class="content-area" >
106
+ { vnode}
107
+ </div>
108
+ }
109
+ }
110
+
111
+ #[ function_component( App ) ]
112
+ fn app ( ) -> Html {
113
+ html ! {
114
+ <div id="result" >
115
+ <Content />
116
+ </div>
117
+ }
118
+ }
119
+
120
+ let s = ServerRenderer :: < App > :: new ( ) . render ( ) . await ;
121
+
122
+ gloo:: utils:: document ( )
123
+ . query_selector ( "#output" )
124
+ . unwrap ( )
125
+ . unwrap ( )
126
+ . set_inner_html ( & s) ;
127
+
128
+ sleep ( Duration :: from_millis ( 10 ) ) . await ;
129
+
130
+ Renderer :: < App > :: with_root ( gloo:: utils:: document ( ) . get_element_by_id ( "output" ) . unwrap ( ) )
131
+ . hydrate ( ) ;
132
+
133
+ let result = obtain_result ( ) ;
134
+
135
+ // still hydrating, during hydration, the server rendered result is shown.
136
+ assert_eq ! (
137
+ result. as_str( ) ,
138
+ r#"<!--<[hydration::hydration_with_raw::{{closure}}::Content]>--><div class="content-area"><!--<##>--><div><p>Hello World</p></div><!--</##>--></div><!--</[hydration::hydration_with_raw::{{closure}}::Content]>-->"#
139
+ ) ;
140
+
141
+ sleep ( Duration :: from_millis ( 50 ) ) . await ;
142
+
143
+ let result = obtain_result ( ) ;
144
+
145
+ // hydrated.
146
+ assert_eq ! (
147
+ result. as_str( ) ,
148
+ r#"<div class="content-area"><div><p>Hello World</p></div></div>"#
149
+ ) ;
150
+ }
151
+
97
152
#[ wasm_bindgen_test]
98
153
async fn hydration_with_suspense ( ) {
99
154
#[ derive( PartialEq ) ]
0 commit comments