Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use turbolinks:before-visit, not turbolinks:before-cache #644

Merged
merged 1 commit into from
Dec 25, 2016
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
## [Unreleased]
*Please add entries here for your pull requests.*

## [6.3.3] - 2016-12-25
- By using the hook on `turbolinks:before-visit` to unmount the components, we can ensure that components are unmounted even when Turbolinks cache is disabled. Previously, we used `turbolinks:before-cache` event hook. [#644](https://github.com/shakacode/react_on_rails/pull/644) by [volkanunsal](https://github.com/volkanunsal).

## [6.3.2] - 2016-12-5
##### Fixed
- The `react_component` method was raising a `NameError` when `ReactOnRailsHelper` was included in a plain object. [#636](https://github.com/shakacode/react_on_rails/pull/636) by [jtibbertsma](https://github.com/jtibbertsma).
Expand Down Expand Up @@ -404,7 +407,8 @@ Best done with Object destructing:
##### Fixed
- Fix several generator related issues.

[Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.3.2...master
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.3.3...master
[6.3.3]: https://github.com/shakacode/react_on_rails/compare/6.3.2...6.3.3
[6.3.2]: https://github.com/shakacode/react_on_rails/compare/6.3.1...6.3.2
[6.3.1]: https://github.com/shakacode/react_on_rails/compare/6.3.0...6.3.1
[6.3.0]: https://github.com/shakacode/react_on_rails/compare/6.2.1...6.3.0
Expand Down
7 changes: 3 additions & 4 deletions node_package/src/clientStartup.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ export function clientStartup(context) {
reactOnRailsPageLoaded();
} else if (turbolinksVersion5()) {
debugTurbolinks(
'USING TURBOLINKS 5: document added event listeners turbolinks:before-cache and ' +
'turbolinks:load.',
);
document.addEventListener('turbolinks:before-cache', reactOnRailsPageUnloaded);
'USING TURBOLINKS 5: document added event listeners ' +
' turbolinks:before-visit and turbolinks:load.');
document.addEventListener('turbolinks:before-visit', reactOnRailsPageUnloaded);
document.addEventListener('turbolinks:load', reactOnRailsPageLoaded);
} else {
debugTurbolinks(
Expand Down
2 changes: 0 additions & 2 deletions spec/dummy/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 2.7.2'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
Expand Down
2 changes: 2 additions & 0 deletions spec/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<head>
<title>Dummy</title>

<%= yield :head %>

<%= env_stylesheet_link_tag(static: 'application_static',
hot: 'application_non_webpack',
media: 'all',
Expand Down
3 changes: 3 additions & 0 deletions spec/dummy/app/views/pages/_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@
<li>
<%= link_to "CSS Modules Images Fonts Example", css_modules_images_fonts_example_path %>
</li>
<li>
<%= link_to "Turbolinks Cache Disabled Example", turbolinks_cache_disabled_path %>
</li>
</ul>
<hr/>
10 changes: 10 additions & 0 deletions spec/dummy/app/views/pages/turbolinks_cache_disabled.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% content_for(:head) do %>
<meta name="turbolinks-cache-control" content="no-cache">
<% end %>

<%= render "header" %>

<%= react_component("CacheDisabled") %>
<hr/>

This page demonstrates that components are still unmounted when the Turbolinks cache is disabled.
19 changes: 19 additions & 0 deletions spec/dummy/client/app/components/CacheDisabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

export default class CacheDisabled extends React.Component {

componentWillUnmount() {
console.log('CacheDisabled#componentWillUnmount')
}

render() {
return (
<div className="container">
<h2>Turbolinks cache is disabled</h2>
<p>
Must call componentWillUnmount.
</p>
</div>
);
}
}
2 changes: 2 additions & 0 deletions spec/dummy/client/app/startup/clientRegistration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ReduxApp from './ClientReduxApp';
import ReduxSharedStoreApp from './ClientReduxSharedStoreApp';
import RouterApp from './ClientRouterApp';
import PureComponent from '../components/PureComponent';
import CacheDisabled from '../components/CacheDisabled';
import CssModulesImagesFontsExample from '../components/CssModulesImagesFontsExample';
import ManualRenderApp from './ManualRenderAppRenderer';
import DeferredRenderApp from './DeferredRenderAppRenderer';
Expand All @@ -31,6 +32,7 @@ ReactOnRails.register({
CssModulesImagesFontsExample,
ManualRenderApp,
DeferredRenderApp,
CacheDisabled
});

ReactOnRails.registerStore({
Expand Down
1 change: 1 addition & 0 deletions spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
get "react_router(/*all)" => "react_router#index", as: :react_router
get "pure_component" => "pages#pure_component"
get "css_modules_images_fonts_example" => "pages#css_modules_images_fonts_example"
get "turbolinks_cache_disabled" => "pages#turbolinks_cache_disabled"
end