Skip to content

Commit 25cd6f1

Browse files
committed
remove internally used properties before server render
(also adds a test for spilling the internal properties to the DOM)
1 parent bff5d43 commit 25cd6f1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/react/rails/view_helper.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ def react_component(name, args = {}, options = {}, &block)
1515
data[:react_class] = name
1616
data[:react_props] = args.to_json unless args.empty?
1717
end
18-
html_tag = html_options.delete(:tag) || :div
19-
18+
html_tag = html_options[:tag] || :div
19+
20+
# remove internally used properties so they aren't rendered to DOM
21+
[:tag, :prerender].each{|prop| html_options.delete(prop)}
22+
2023
content_tag(html_tag, '', html_options, &block)
2124
end
2225

test/view_helper_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,10 @@ class ViewHelperTest < ActionDispatch::IntegrationTest
8383
assert_match /data-react-checksum/, page.html
8484
assert_match /yep/, page.find("#status").text
8585
end
86+
87+
test 'react server rendering does not include internal properties' do
88+
visit '/server/1'
89+
assert_no_match /tag=/, page.html
90+
assert_no_match /prerender=/, page.html
91+
end
8692
end

0 commit comments

Comments
 (0)