-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
Added callbacks to the Helper to allow you to insert additional JS before and after the server rendering. #287
Conversation
Removed the additional version info at the end.
#{initialize_redux_stores} | ||
var props = #{props_string(props)}; | ||
return ReactOnRails.serverRenderReactComponent({ | ||
name: '#{react_component_name}', | ||
domNodeId: '#{dom_id}', | ||
name: "#{react_component_name}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martyphee This would not pass the linter. ;-) No double quotes in JS code. So please stick to single quotes. Remember, we're generating JS here, so flip the JS button in your head.
Could you please create the changes for README of how this work? I think we should make the inline JS code something that one puts in the react_on_rails.rb initializer with the properties before_server_render_js Reviewed 3 of 3 files at r1. .gitignore, line 32 [r1] (raw file): Comments from the review on Reviewable.io |
Need to move to using the config file for the the callback of what to generate. Also, we should pass in information on what is being rendered, so that can be used by some ruby code to dynamically create the before and after JS code. How about if the config file defines your class name where you put in the methods you wanted to monkey patch? So you can create a class in the config file and we'll pass in the params that we have (react_component_name, dom_id, etc.) to the constructor of the object, and the creator of this will create a couple methods to return the custom javascript. Basically, this is just a more elegant plugin than the monkey patching. Review status: 1 of 3 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. README.md, line 454 [r3] (raw file): No reason to use monkey patching. Comments from the review on Reviewable.io |
@martyphee Any updates on this one? |
Sorry, no. It's been a busy week. I'll work on this today. Shouldn't On Fri, Feb 26, 2016 at 6:24 PM, Justin Gordon notifications@github.com
|
Just pushed an update. I'm having trouble running |
@martyphee Any updates? |
@martyphee I'm going to be putting in some time this weekend, so let me know if you have any updates. |
I did push updates to this about a week ago. On Sat, Mar 12, 2016 at 12:45 PM, Justin Gordon notifications@github.com
|
Hi @martyphee. It's getting there. I left you some comments. Reviewed 1 of 2 files at r2, 1 of 1 files at r3, 2 of 5 files at r5, 4 of 4 files at r6. README.md, line 454 [r3] (raw file): README.md, line 182 [r6] (raw file): app/helpers/react_on_rails_helper.rb, line 238 [r6] (raw file): In config.server_rendering_callback_class = MyServerRenderingCallback I don't see the need for any sort of dynamic instantiation. lib/react_on_rails/configuration.rb, line 24 [r6] (raw file): we can default to nil if no server_rendering_callback_class lib/react_on_rails/renderer.rb, line 3 [r6] (raw file): However, I'm not seeing the need to have a "NULL OBJECT" for this. spec/dummy/Gemfile.lock, line 275 [r6] (raw file): Comments from the review on Reviewable.io |
Please rebase on top of master to a single commit and let me know if you're ready. I'm about to release v4. |
@martyphee Back to the need of this...Why are the JS of translations not included in your bundle? Is this to save space in the bundle size? |
@martyphee We need a pretty good example of this. The feature is not hard. I just want to make sure the feature is needed. |
Sorry, just got back from London. We don't include all the translations for each country in the build. Only We're not moving anytime soon it seems so unless someone else has a need On Wed, Mar 16, 2016 at 6:03 PM, Justin Gordon notifications@github.com
|
@martyphee This like a potentially useful feature. Possibly there should be different webpack bundles instead? See #343. That way, you could have a helper pick the right server rendering webpack file. @lucke84 and @jopdeklein, what do you think of this? |
@justin808 Focusing on the use case of the locales; we are actually also facing the need to inject just one locale, the Intl and moment locale files are huge so it makes sense to not load them all. However we only need that for the client (we're currently injecting the current locale as inline JS from the template - not ideal but we wanted to avoid the extra external request). For SSR we've just bundled all available locales and pick the correct one runtime based on passed props to the component. Either way I think this solution is a better approach than to have separate bundles for each locale (eg: |
@jopdeklein I'm thinking that we go with @martyphee's feature first. There's a lot more simplicity in creating ONE server side webpack bundle. Different client bundles make a lot of sense. @alexfedoseev @thewoolleyman @robwise @martyphee @jbhatab Agree? |
Yeah, I'm going to try to get back to this tomorrow and get it merged in. On Thu, Mar 24, 2016 at 6:44 PM, Justin Gordon notifications@github.com
|
@justin808 I agree, @lucke84 and I will document our rationale for supporting multiple bundles, but in principle you're right, we could likely get away with separated client bundles and a combined bundle for server rendering. I see no issues going ahead with integrating this PR. 👍 |
@jopdeklein @martyphee Just jumping into this one. Trying to identify the main issue that the before and after hooks are addressing. Could you just load in the I18n file in the server rendered file? |
If the issue is locales, we should have an example. It would be awesome to have a PR on top of https://github.com/shakacode/react-webpack-rails-tutorial/ showing this. With a solid example, then we have something to go on. Note, in the next couple of days, I'm going to be changing the JavaScript generator function calls for stores and components so we pass an object containing properties like: { url, path, search, hash, {...otherThingsFromRailsRequestLikeLocale} } Thus, you can configure the locale in your generator function, maybe merging the locale into your props on the client side and only requiring the translation file needed for the given locale. How's that sound? |
@justin808 I like that direction more too. Definitely wanna know if that solves your problems though. I just would like to avoid adding more things like this to the gem if possible. |
This did solve our issue when I did a POC of our react app using We have to load a JS file per locale before rendering on the server so that On Fri, Mar 25, 2016 at 2:52 PM, Blaine Hatab notifications@github.com
|
What is "this"? If you can point me to a git repo that shows "this" in action, that would be really helpful. For server rendering with locales, I'm thinking that the server and client code should be the same, and we should be doing an inline "require" of the right locale file based on a value passed into the generator doing the rendering. I'm guessing that any special code on the hooks you have --> that could also have some logic in the generator function and use a locale value passed in. |
"this"? deliveroo.co.uk. It's currently angular but we're rewriting it in I can't point you to the repo since it's private.
On Fri, Mar 25, 2016 at 3:45 PM, Justin Gordon notifications@github.com
|
@martyphee could you put the js you need in a layout or view file before the component all since that will be server rendered? |
We need to have the i18n available during server rendering so that it has
On Fri, Mar 25, 2016 at 4:12 PM, Blaine Hatab notifications@github.com
|
Let's move this discussion over to #345. I think this will do everything this was going to do and a whole lot more. |
@martyphee Please see #345. I plan to merge later today. I think this should meet your needs. |
@martyphee I'd like to see if we can handle your case for the 5.0.0 final release. |
@earaujoassis, please discuss with @martyphee if we can solve the localization issue without the extra hooks. I'm very happy to put in the hooks, but I need a shareable example that justifies this. |
@martyphee Should we close this? |
Yes. On Wednesday, April 20, 2016, Justin Gordon notifications@github.com
|
I think the hooks + railsContext are great additions. Hooks could solve issues around server rendering that client rendering doesn't need to concern itself about, and thus doesn't need to be in railsContext. For example you may need to construct dependancies (eg, a psuedo-window object) so server rendering doesn't error, etc. +1 for hooks |
@stuarthannig Feel free to create a new PR with an example that justifies this feature. |
This PR adds pre-render and after-render hooks to allow the insertion of JS before and after server compiling.
Our use case is to allow us to insert i18n js before server rendering so that we have the proper language file.