-
-
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
Return markup hash form react component helper #800
Return markup hash form react component helper #800
Conversation
@udovenko AWESOME start. Besides the comments below, we need:
Reviewed 14 of 14 files at r1. app/helpers/react_on_rails_helper.rb, line 121 at r1 (raw file):
Let's create a Hash of params and pass this to both methods. For more than 2 params, I prefer named params, or in our case, a hash of params. app/helpers/react_on_rails_helper.rb, line 230 at r1 (raw file):
app/helpers/react_on_rails_helper.rb, line 243 at r1 (raw file):
Why only the first character as downcased? Note, downcase copies: https://ruby-doc.org/core-2.1.0/String.html#method-i-downcase while I'd suggest we consider using the same key in the hash to mean the component, rather than the accessory information. app/helpers/react_on_rails_helper.rb, line 245 at r1 (raw file):
display the expected component name in the error message app/helpers/react_on_rails_helper.rb, line 261 at r1 (raw file):
docs/api/javascript-api.md, line 11 at r1 (raw file):
or, in the case of server rendering, you may use a "generator function" to return a React component or an object with the following shape: See the example in /docs/additional-reading/react-helmut.md docs/api/javascript-api.md, line 12 at r1 (raw file):
switch to In this case rendered component HTML must be returned spec/dummy/app/views/pages/rendered_htmls.erb, line 9 at r1 (raw file):
I really don't like having the component name be <%= render_hash["componentHtml"] %> CC: @alexfedoseev @robwise spec/dummy/client/app/startup/clientRegistration.jsx, line 49 at r1 (raw file):
I think we need to change the name from spec/dummy/client/app/startup/ClientRenderedHtmls.jsx, line 9 at r1 (raw file):
please fix up, trim up comments to reflect this example spec/dummy/client/app/startup/ServerRenderedHtmls.jsx, line 24 at r1 (raw file):
const renderedHtml = {
componentHtml,
title: helmet.title.toString(),
}; Comments from Reviewable |
Review status: all files reviewed at latest revision, 11 unresolved discussions, some commit checks failed. app/helpers/react_on_rails_helper.rb, line 121 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
Yes, that's reasonable. app/helpers/react_on_rails_helper.rb, line 230 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
Will fix... app/helpers/react_on_rails_helper.rb, line 243 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
So we will access the component by the same key as used for its registration? app/helpers/react_on_rails_helper.rb, line 245 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
Will do... app/helpers/react_on_rails_helper.rb, line 261 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
ok docs/api/javascript-api.md, line 11 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
See comment above... docs/api/javascript-api.md, line 12 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
In this case rendered component must be under the key that matches its registration name (that is passed as component_name to react_component helper) inside componentHtml object. Suppose we registered component as App:
spec/dummy/app/views/pages/rendered_htmls.erb, line 9 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
The name of the hash key here must be the same as the key for component registration. I can register it as "ReactHelmetApp" then... spec/dummy/client/app/startup/clientRegistration.jsx, line 49 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
see above... Comments from Reviewable |
react-hElmet... Review status: all files reviewed at latest revision, 11 unresolved discussions, some commit checks failed. Comments from Reviewable |
Review status: 5 of 14 files reviewed at latest revision, 11 unresolved discussions, some commit checks failed. app/helpers/react_on_rails_helper.rb, line 121 at r1 (raw file): Previously, udovenko (Denis Udovenko) wrote…
Done. app/helpers/react_on_rails_helper.rb, line 230 at r1 (raw file): Previously, udovenko (Denis Udovenko) wrote…
Done. app/helpers/react_on_rails_helper.rb, line 243 at r1 (raw file): Previously, udovenko (Denis Udovenko) wrote…
Done. app/helpers/react_on_rails_helper.rb, line 245 at r1 (raw file): Previously, udovenko (Denis Udovenko) wrote…
Done. spec/dummy/client/app/startup/ReactHelmetClientApp.jsx, line 9 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. spec/dummy/client/app/startup/ReactHelmetServerApp.jsx, line 24 at r1 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. Comments from Reviewable |
Review status: 4 of 16 files reviewed at latest revision, 11 unresolved discussions, some commit checks failed. app/helpers/react_on_rails_helper.rb, line 261 at r1 (raw file): Previously, udovenko (Denis Udovenko) wrote…
Done. docs/api/javascript-api.md, line 11 at r1 (raw file): Previously, udovenko (Denis Udovenko) wrote…
Done. docs/api/javascript-api.md, line 12 at r1 (raw file): Previously, udovenko (Denis Udovenko) wrote…
Done. spec/dummy/app/views/pages/react_helmet.erb, line 9 at r1 (raw file): Previously, udovenko (Denis Udovenko) wrote…
Done. spec/dummy/client/app/startup/clientRegistration.jsx, line 49 at r1 (raw file): Previously, udovenko (Denis Udovenko) wrote…
Done. spec/dummy/client/app/startup/ReactHelmetClientApp.jsx, line 9 at r1 (raw file): Previously, udovenko (Denis Udovenko) wrote…
Done. Comments from Reviewable |
@justin808 I think I've fixed all your review notices. Hope I didn't miss anything... |
@udovenko The main change is to fix the return keys. See below. I'll try to get feedback from @robwise and @alexfedoseev on the API. Reviewed 18 of 18 files at r2. CHANGELOG.md, line 11 at r2 (raw file):
I think you wanted to use a single back tick, rather than three. README.md, line 342 at r2 (raw file):
For server rendering, if you wish to return multiple HTML strings from a generator function, such when using nfl/react-helmut, you may return an { renderedHtml: { componentHtml, customKey1, customKey2} } app/helpers/react_on_rails_helper.rb, line 227 at r2 (raw file):
Please assign the params to local variables. It's a bummer that we can't use named parameters due to a desire to maintain Ruby 2.0 compat. app/helpers/react_on_rails_helper.rb, line 258 at r2 (raw file):
I thought we're switching to a constant of app/helpers/react_on_rails_helper.rb, line 259 at r2 (raw file):
I think it's awkward that the code inside of the the generator function needs to know it's name to work. If the name changes, this will be fragile. I'd rather see that we fix the shape of the return Object: @alexfedoseev @robwise, any opinions on this? docs/additional-reading/react-helmet.md, line 1 at r2 (raw file):
single backtick vs triple? docs/additional-reading/react-helmet.md, line 13 at r2 (raw file):
please use const componentHtml = renderToString(<App {...props} />);
const helmet = Helmet.renderStatic();
const renderedHtml = {
componentHtml,
title: helmet.title.toString(),
}; docs/additional-reading/react-helmet.md, line 74 at r2 (raw file): Quoted 7 lines of code…> ```ruby > <% render_hash = react_component("ReactHelmetApp", prerender: true, props: { hello: "world" }, trace: true) %> > > <% content_for :title do %> > <%= render_hash['title'] %> > <% end %> > > <%= render_hash["ReactHelmetApp"] %> ```@alexfedoseev @robwise How about this: <% react_helmut_app = react_component("ReactHelmetApp", prerender: true, props: { hello: "world" }, trace: true) %>
<% content_for :title do %>
<%= react_helmut_app['title'] %>
<% end %>
<%= react_helmut_app["componentHtml"] %> docs/api/javascript-api.md, line 12 at r2 (raw file):
Let's modify the doc to reflect this (no markdown, naturally). For server rendering, if you wish to return multiple HTML strings from a generator function, such when using nfl/react-helmut, you may return an { renderedHtml: { componentHtml, customKey1, customKey2} } node_package/tests/ReactOnRails.test.js, line 138 at r2 (raw file):
Why did this change? Was this an old bug? spec/dummy/app/views/pages/react_helmet.erb, line 9 at r2 (raw file):
see example from docs above. Comments from Reviewable |
Review status: 13 of 20 files reviewed at latest revision, 22 unresolved discussions, some commit checks failed. CHANGELOG.md, line 11 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. README.md, line 342 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. app/helpers/react_on_rails_helper.rb, line 227 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. app/helpers/react_on_rails_helper.rb, line 258 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. app/helpers/react_on_rails_helper.rb, line 259 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. docs/additional-reading/react-helmet.md, line 1 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. docs/additional-reading/react-helmet.md, line 13 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. docs/additional-reading/react-helmet.md, line 74 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. docs/api/javascript-api.md, line 12 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. node_package/tests/ReactOnRails.test.js, line 138 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
This bug came from my previous PR. setStore method expects store instance, not store generator function. This change does not affect test results but I think this should be fixed to avoid misleading for other contributors. spec/dummy/app/views/pages/react_helmet.erb, line 9 at r2 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. Comments from Reviewable |
@justin808 It's done I think. |
see comments below Reviewed 2 of 18 files at r2, 7 of 8 files at r3. app/helpers/react_on_rails_helper.rb, line 228 at r4 (raw file):
nifty! @robwise not as good as ES6 destructuring! HOWEVER: https://robots.thoughtbot.com/ruby-2-keyword-arguments Ruby 2.0 introduced keyword arguments! Take a look at this: Only very old Ruby < 2 required hash for params! I'm glad I caught that. app/helpers/react_on_rails_helper.rb, line 232 at r4 (raw file):
see that PR 651 and see how required params are done app/helpers/react_on_rails_helper.rb, line 261 at r4 (raw file):
This should be declared as a Ruby const at the top of this file, all caps app/helpers/react_on_rails_helper.rb, line 263 at r4 (raw file):
unless params[:server_rendered_html][COMPONENT_HTML_KEY] Comments from Reviewable |
Review status: 18 of 19 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. app/helpers/react_on_rails_helper.rb, line 228 at r4 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. app/helpers/react_on_rails_helper.rb, line 232 at r4 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. app/helpers/react_on_rails_helper.rb, line 261 at r4 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. app/helpers/react_on_rails_helper.rb, line 263 at r4 (raw file): Previously, justin808 (Justin Gordon) wrote…
Done. Comments from Reviewable |
@justin808 Done... |
Great job @udovenko! Reviewed 1 of 1 files at r6. Comments from Reviewable |
863fd08
to
d612f46
Compare
Reviewed 4 of 4 files at r7. Comments from Reviewable |
…on on the server * Implement handling of Hash result of server_rendered_react_component_html in react_on_rails helper * Implement additional example page for server rendered HTML that shows usage of htmlResult object
* Add conditional title to dummy app layout * Implement rendering title string in generator function on server * Add test for conditional title to integration_spec * Refactor code in react_on_rails helper
* Now test page yields title rendered by ReactHelmet * Add tests with disabled JS to integration spec to ensure correct title rendering on server * Mark HTML strings other than component HTML (composed with props and console script) as html_safe
* Renamed example page to react_helmet * Changed route to example page * Renamed component registration to ReactHelmetApp * Additional refactoring
* Create additional-reading/react-helmet.mb * Fix comments for generator function * Update javascript-api.md
* Update README.md * Update CHANGELOG.md
…ponentHtml * Implement constant key usage in #build_react_component_result_for_server_rendered_hash method of react_on_rails helper * Updated generator function for server rendering * Additional refactoring
* Fixed additional-reading/react-helmet.md * Updated react_helmet.erb template accordingly
* Implement required params for #build_react_component_result_for... methods * Moved component_html_key to the constant
1fab7e2
to
dd1190d
Compare
* Update react-helmet to v5.0.3 to resolve PropTypes warnings * Fixed rubocop warnings
Reviewed 4 of 4 files at r8. spec/dummy/client/package.json, line 36 at r8 (raw file):
no why? Comments from Reviewable |
Review status: all files reviewed at latest revision, 1 unresolved discussion, some commit checks failed. Comments from Reviewable |
This change is