Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/assets/javascripts/react_ujs.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ var ReactRailsUJS = {

// helper method for the mount and unmount methods to find the
// `data-react-class` DOM elements
findDOMNodes: function(selector) {
findDOMNodes: function(searchSelector) {
var classNameAttr = ReactRailsUJS.CLASS_NAME_ATTR
// we will use fully qualified paths as we do not bind the callbacks
var selector, parent;
Expand Down Expand Up @@ -502,4 +502,4 @@ module.exports = function(reqctx) {

/***/ })
/******/ ]);
});
});
4 changes: 2 additions & 2 deletions react_ujs/dist/react_ujs.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ var ReactRailsUJS = {

// helper method for the mount and unmount methods to find the
// `data-react-class` DOM elements
findDOMNodes: function(selector) {
findDOMNodes: function(searchSelector) {
var classNameAttr = ReactRailsUJS.CLASS_NAME_ATTR
// we will use fully qualified paths as we do not bind the callbacks
var selector, parent;
Expand Down Expand Up @@ -502,4 +502,4 @@ module.exports = function(reqctx) {

/***/ })
/******/ ]);
});
});
2 changes: 1 addition & 1 deletion react_ujs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var ReactRailsUJS = {

// helper method for the mount and unmount methods to find the
// `data-react-class` DOM elements
findDOMNodes: function(selector) {
findDOMNodes: function(searchSelector) {
var classNameAttr = ReactRailsUJS.CLASS_NAME_ATTR
// we will use fully qualified paths as we do not bind the callbacks
var selector, parent;
Expand Down
9 changes: 6 additions & 3 deletions test/dummy/app/views/pages/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<ul>
<li><%= link_to 'Alice', page_path(:id => 0) %></li>
<li><%= link_to 'Bob', page_path(:id => 1) %></li>
<li><%= link_to 'Alice', page_path(id: 0) %></li>
<li><%= link_to 'Bob', page_path(id: 1) %></li>
</ul>

<div id='component-parent'>
<%= react_component 'GreetingMessage', { :name => @name }, { :id => 'component', prerender: @prerender } %>
<%= react_component 'GreetingMessage', { name: @name }, { id: 'component', prerender: @prerender } %>
<ul>
<%= react_component 'Todo', { todo: 'Another Component' }, { id: 'todo', prerender: @prerender } %>
</ul>
</div>

<button onClick="ReactRailsUJS.unmountComponents('#component-parent')">Unmount by parent selector</button>
Expand Down
2 changes: 1 addition & 1 deletion test/react/rails/controller_lifecycle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def teardown
test "it calls setup and teardown methods" do
get '/pages/1?param_test=123'
helper_obj = controller.__react_component_helper
lifecycle_steps = ["123", :react_component, :teardown]
lifecycle_steps = ["123", :react_component, :react_component, :teardown]
assert_equal(lifecycle_steps, helper_obj.events)
end

Expand Down
15 changes: 15 additions & 0 deletions test/react/rails/react_rails_ujs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ def refute_greeting(page, greeting)
assert_greeting(page, 'Hello Bob')
end

test 'react_ujs does not unmount components that do not match a selector reference for the component' do
visit '/pages/1'
assert_greeting page, 'Hello Bob'
assert page.has_content?('Another Component'), page.body

page.click_button "Unmount by own selector"
refute_greeting(page, 'Hello Bob')
assert page.has_content?('Another Component'), page.body

page.click_button "Mount by own selector"
assert_greeting(page, 'Hello Bob')
assert page.has_content?('Another Component'), page.body
end


test 'react_ujs can unmount/mount using a dom node context' do
visit '/pages/1'
assert_greeting(page, 'Hello Bob')
Expand Down