-
Hey! I hope I can find some help here :) I recently upgraded from webpacker to shakapacker 6.6.0 and also webpack 4 to 5. I have an Before the upgrade, it was loaded in the I had to move this to the body, because while keeping this in the So no JS is loaded in the head (only some stuff with javascript_include_tag calls from sprockets)., everything in the body. Almost everything is working fine, but still some parts are broken, especially my After 2-3 Turbolink visits, I get the useContext Invalid Hooks Error. If I move my main javascript pack (where I also import react_on_rails and register my component) back into the I'm sure this is because of turbolinks and the way the JS is loaded and cached. And surely I am doing something wrong. Does anyone have advice? Rails 6.1.7.4 Thanks in advance 😇 🙏🏻 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I'd recommend trying to split turbolinks out of the main bundle & put it back into the head. |
Beta Was this translation helpful? Give feedback.
-
Hello! It seems like you're facing some issues with the integration of React on Rails and Turbolinks after upgrading to Shakapacker 6.6.0 and Webpack 5. I understand that moving your main JavaScript pack back into the Here are a few suggestions you can try:
It's important to note that the specific issue you're facing may require further investigation and debugging. You might need to go through your code and identify any potential conflicts or areas where the integration is not working as expected. I hope these suggestions help resolve your issue. If you have any further questions or need more assistance, please feel free to ask! |
Beta Was this translation helpful? Give feedback.
Hello! It seems like you're facing some issues with the integration of React on Rails and Turbolinks after upgrading to Shakapacker 6.6.0 and Webpack 5. I understand that moving your main JavaScript pack back into the
<head>
of the DOM solves theuseContext
Invalid Hooks Error, but causes other bugs.Here are a few suggestions you can try:
Ensure correct configuration: Verify that your Webpack configuration is set up correctly for React on Rails. Make sure that React and ReactDOM are excluded from the global scope and are properly bundled as external dependencies.
Disable Turbolinks for specific pages: If the issue mainly occurs on certain pages where Turbolinks is not required, you c…