From 0af02f66b3ca0447f2ac9293f09af717efc085b7 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Fri, 10 Jul 2015 09:41:10 +1000 Subject: [PATCH] remove unmountComponents on window unload --- README.md | 5 ++--- lib/assets/javascripts/react_ujs.js.erb | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cd2fe691f..a9f86de95 100644 --- a/README.md +++ b/README.md @@ -129,10 +129,9 @@ The __view helper__ puts a `div` on the page with the requested component class ``` On page load, the __`react_ujs` driver__ will scan the page and mount components using `data-react-class` -and `data-react-props`. Before page unload, it will unmount components (if you want to disable this behavior, -remove `data-react-class` attribute in `componentDidMount`). +and `data-react-props`. -`react_ujs` uses Turbolinks events if they're available, otherwise, it uses native events. +If Turbolinks is present components are mounted on the `page:change` event, and unmounted on `page:before-unload`. __Turbolinks >= 2.4.0__ is recommended because it exposes better events. The view helper's signature is: diff --git a/lib/assets/javascripts/react_ujs.js.erb b/lib/assets/javascripts/react_ujs.js.erb index 1d2fabfa9..c80f464bb 100644 --- a/lib/assets/javascripts/react_ujs.js.erb +++ b/lib/assets/javascripts/react_ujs.js.erb @@ -89,10 +89,8 @@ function handleNativeEvents() { if ($) { $(function() {window.ReactRailsUJS.mountComponents()}); - $(window).unload(function() {window.ReactRailsUJS.unmountComponents()}); } else { document.addEventListener('DOMContentLoaded', function() {window.ReactRailsUJS.mountComponents()}); - window.addEventListener('unload', function() {window.ReactRailsUJS.unmountComponents()}); } }