You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use pjax on an Rails app we are slowly converting from older JS to React.
The issue: Components included withreact_component do render on the first page load, but don't render on pjax page changes. The docs suggest they should.
I'm not sure if this is just an issue with our config or with the way react-rails handles pjax interaction. I saw #742 but the comments don't seem to fix the issue I'm seeing.
When you browse to a new page and back, components in the area loaded by pjax do not render:
Files of note: javascripts/application.js initializes pjax
Components are included in welcome/index.html.erb, welcome/two.html.erb, and application.html.erb.
Workaround I found: if I listen to pjax:end in javascripts/application.js and call ReactRailsUJS.mountComponents(), the app behaves as expected:
$(document).on('pjax:end', function() {
console.log('pjax:end');
ReactRailsUJS.mountComponents() // This forces components to re-render
})
System configuration
Sprockets or Webpacker version: 4.2.2 React-Rails version: 2.6.1 React_UJS version: not clear Rails version: 5.1.7
The text was updated successfully, but these errors were encountered:
We use pjax on an Rails app we are slowly converting from older JS to React.
The issue: Components included with
react_component
do render on the first page load, but don't render on pjax page changes. The docs suggest they should.I'm not sure if this is just an issue with our config or with the way react-rails handles pjax interaction. I saw #742 but the comments don't seem to fix the issue I'm seeing.
I made a small test app to demonstrate this issue:
https://github.com/hampelm/react-rails-pjax-debug
When you load the app, all components render:
When you browse to a new page and back, components in the area loaded by pjax do not render:
Files of note:
javascripts/application.js
initializes pjaxComponents are included in
welcome/index.html.erb
,welcome/two.html.erb
, andapplication.html.erb
.Workaround I found: if I listen to
pjax:end
injavascripts/application.js
and callReactRailsUJS.mountComponents()
, the app behaves as expected:System configuration
Sprockets or Webpacker version: 4.2.2
React-Rails version: 2.6.1
React_UJS version: not clear
Rails version: 5.1.7
The text was updated successfully, but these errors were encountered: