Skip to content

Commit

Permalink
fix empty html comments
Browse files Browse the repository at this point in the history
is related to facebook/react#14725
  • Loading branch information
Tarnadas committed Dec 6, 2019
1 parent 4176af5 commit 337f93d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/__tests__/ReactServerRendering-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ describe('ReactDOMServer', () => {
'>' +
'<span' +
'>' +
'My name is child' +
// TODO where does <!-- --> come from?
// 'My name is <!-- -->child' +
'My name is <!-- -->child' +
'</span>' +
'</div>',
),
Expand Down Expand Up @@ -140,9 +138,7 @@ describe('ReactDOMServer', () => {
'data-reactroot' +
'=""' +
'>' +
'Component name: TestComponent' +
// TODO
// 'Component name: <!-- -->TestComponent' +
'Component name: <!-- -->TestComponent' +
'</span>',
),
);
Expand Down
24 changes: 18 additions & 6 deletions src/rust/renderer/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,17 @@ fn render_intrinsic(
#[cfg(debug_assertions)]
web_sys::console::log_2(&"PROPS".into(), &props);

let mut is_first = true;

if let Some(children) = props.children() {
if let Some(children) = children.dyn_ref::<js_sys::Array>() {
for child in children.values() {
if !is_static && !is_first {
let comment = dom.create_comment(Tendril::from(" "));
element.children.borrow_mut().push(comment);
} else {
is_first = false;
}
render_intrinsic_to_string(child?.into(), element.clone(), dom, is_static);
}
} else {
Expand Down Expand Up @@ -208,16 +216,20 @@ fn render_intrinsic_to_string(
match js_val.dyn_ref::<JsString>() {
Some(js_string) => {
let s: String = js_string.into();
element
.children
.borrow_mut()
.push(Node::new(NodeData::Text {
contents: RefCell::new(Tendril::from(s)),
}));
render_text_component(element, s);
}
None => {
let jsx = js_val.unchecked_ref::<Jsx>();
render_jsx_to_string(jsx, dom, Some(element.clone()), false, is_static).unwrap();
}
};
}

fn render_text_component(element: Rc<Node>, s: String) {
element
.children
.borrow_mut()
.push(Node::new(NodeData::Text {
contents: RefCell::new(Tendril::from(s)),
}));
}

0 comments on commit 337f93d

Please sign in to comment.