-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
How to properly load multiple react components in HTML views with beta 7 #3018
Comments
In simpler words, would it be possible to make the behavior of
the same as
Exemple: Let's say entrypoint_2 loads a React application. Scenario 1: React app loads, state change don't work (no refresh) |
One thing just so it doesn't confuse other people looking at this, if you are using the beta you should no longer need to use As for the specific issue you mention, where loading multiple entrypoints in the same layout file using separate |
By the way:
I would advise against changing "@rails/webpacker": "6.0.0.beta-7" |
Thanks a lot for the feedback! We will continue like this and adjust if another solution comes up. |
Hi!
I am working on an existing app that used to be mostly HTML views with a bit of JQuery logic to interact with controllers in some places. We recently started implementing some React components in TypeScript to replace the JQuery logic.
I am trying to wrap my head around how to best handle loading components and how not to interfere with other JavaScript libraries in the project (for example Amplitude tracking system).
The first try was successful. We had the controller return a specific layout that would load the parent component, which basically was the entire page and would then render child components.
The subsequent tries are a bit harder: we have more nimble components that we would like to render within HTML views. Those views render normal HTML content, in the main application layout, but in some places we would like to inject a React component by attaching it to a specific HTML element.
For each group of React components, we have a specific
entrypoint
injavascript/pack
.We initially tried loading them with
javascript_pack_tag
but the entrypoint/components would not load. We then tried withjavascript_packs_with_chunks_tag
. The component would load but no re-render on state change would work and we understood that was because the javascript file for the tracking solution, Amplitude, was being loaded in the general layout withjavascript_packs_with_chunks_tag
. Hence the issue was having multiplejavascript_packs_with_chunks_tag
.As a workaround, we now load every entry point in the same tag within the header, e.g.
<%= javascript_packs_with_chunks_tag 'tracking', 'carts', 'other-entrypoints %>
but we think this might cause performance issues and other but by overloading content.What would be the best approach to this problem of mixing normal HTML with nimble React components + other JavaScript scripts?
We are running
As a side note, to make Webpacker 6.0.0.beta.7 work and avoid issues with
merge
for example, we manually changed the yarn.lock file to make sure it loads the right version and adjusted the integrity accordingly. Theyarn install
would load pre-2 as the version.The text was updated successfully, but these errors were encountered: