Skip to content
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

Doc/xhr hydration examples #1095

Merged
merged 12 commits into from
Jun 1, 2018

Conversation

hchevalier
Copy link
Contributor

@hchevalier hchevalier commented May 27, 2018

#921 (comment)


This change is Reviewable

@coveralls
Copy link

Coverage Status

Coverage remained the same at ?% when pulling bff7bfb on hchevalier:doc/xhr_hydration_examples into 73cf07e on shakacode:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at ?% when pulling bff7bfb on hchevalier:doc/xhr_hydration_examples into 73cf07e on shakacode:master.

@coveralls
Copy link

coveralls commented May 27, 2018

Coverage Status

Coverage remained the same at ?% when pulling f33fda0 on hchevalier:doc/xhr_hydration_examples into 73cf07e on shakacode:master.

<p>
This example demonstrates client side manual rehydration after a component replacement through XHR.<br/><br/>

The "Refresh" button on this page will trigger an asynchrounous refresh of component-container content.<br/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo on "asynchronous"

Components will be prerendered by the server and inserted in the DOM (spec/dummy/app/views/pages/xhr_refresh.js.erb)<br/>
No client rehydration will occur, preventing any event handler to be correctly attached<br/><br/>

Thus, the onChange handler of the HelloWorld component won't trigger whereas the one from HellowWorldRehydratable will, thanks to the "hydrate" javscript event dispacthed from xhr_refresh.js.erb<br />
Copy link
Contributor Author

@hchevalier hchevalier May 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo on "javascript"

@justin808
Copy link
Member

Review status: 0 of 15 files reviewed at latest revision, 2 unresolved discussions.


README.md, line 546 at r2 (raw file):

  Note: client hydration will not trigger for components rendered through XHR. You will have to handle it with javascript.
  For an example, see [spec/dummy/app/views/pages/xhr_refresh.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/pages/xhr_refresh.rb). 
  

red dots mean extra spaces


spec/dummy/app/assets/javascripts/jquery_rails_manifest.js, line 2 at r2 (raw file):

//= require jquery
//= require jquery_ujs

do we really need to use sprockets for jquery?


spec/dummy/app/views/pages/xhr_refresh.html.erb, line 2 at r2 (raw file):

<% provide :other_javascript_tags do %>
  <%= javascript_include_tag 'jquery_rails_manifest', defer: true %>

This should not be needed if we're using the rails/webpacker way.

The jquery bits should be put into the webpacker tag.

This is pre-webpacker: https://github.com/shakacode/react_on_rails/blob/master/spec/dummy_no_webpacker/app/views/layouts/application.html.erb#L19

This is post-webpacker:

https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/app/views/layouts/application.html.erb#L16

this is the post webpacker jquery: https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/package.json#L27,

https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/webpack.client.rails.build.config.js#L106,

https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/webpack.client.base.config.js#L65


spec/dummy/app/views/pages/xhr_refresh.html.erb, line 21 at r2 (raw file):

Previously, hchevalier wrote…

Typo on "asynchronous"

yes, please fix typo!


spec/dummy/app/views/pages/xhr_refresh.html.erb, line 25 at r2 (raw file):

Previously, hchevalier wrote…

Typo on "javascript"

yes, fix!


spec/dummy/client/app/components/HelloWorldRehydratable.js, line 48 at r2 (raw file):

        // See https://github.com/shakacode/react_on_rails/commit/912118445f55c6f59664bf2b9f9ed97779ee71c9
        // You may have to replace "nextElementSibling" by "previousElementSibling" if you use an older version
        domNode = domNode.nextElementSibling;

get the script tag from just querying for the script tag with the where the <script data-dom-id> matches the component's div id.

definitely make sure all this JS passes the linter.


Comments from Reviewable

@justin808
Copy link
Member

Changes requested.


Review status: all files reviewed at latest revision, 6 unresolved discussions.


Comments from Reviewable

@hchevalier
Copy link
Contributor Author

Review status: 9 of 14 files reviewed at latest revision, 4 unresolved discussions.


README.md, line 546 at r2 (raw file):

Previously, justin808 (Justin Gordon) wrote…

red dots mean extra spaces

Done.


spec/dummy/app/views/pages/xhr_refresh.html.erb, line 2 at r2 (raw file):

Previously, justin808 (Justin Gordon) wrote…

This should not be needed if we're using the rails/webpacker way.

The jquery bits should be put into the webpacker tag.

This is pre-webpacker: https://github.com/shakacode/react_on_rails/blob/master/spec/dummy_no_webpacker/app/views/layouts/application.html.erb#L19

This is post-webpacker:

https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/app/views/layouts/application.html.erb#L16

this is the post webpacker jquery: https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/package.json#L27,

https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/webpack.client.rails.build.config.js#L106,

https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/client/webpack.client.base.config.js#L65

Done.


spec/dummy/app/assets/javascripts/jquery_rails_manifest.js, line 2 at r2 (raw file):

Previously, justin808 (Justin Gordon) wrote…

do we really need to use sprockets for jquery?

Done.


spec/dummy/client/app/components/HelloWorldRehydratable.js, line 48 at r2 (raw file):

Previously, justin808 (Justin Gordon) wrote…

get the script tag from just querying for the script tag with the where the <script data-dom-id> matches the component's div id.

definitely make sure all this JS passes the linter.

Done.


Comments from Reviewable

@justin808
Copy link
Member

Some suggestions. Looking good.


Review status: all files reviewed at latest revision, all discussions resolved.


spec/dummy/client/app/startup/clientRegistration.jsx, line 4 at r3 (raw file):

import 'es5-shim';
import 'jquery'
import {} from 'jquery-ujs'

Any explanation for the addition of these?

I think we should use something like this for all of these:


spec/dummy/client/app/components/HelloWorldRehydratable.jsx, line 47 at r3 (raw file):

      // Get component specification <script> tag
      const componentSpecificationTag = document.querySelector(`script[data-dom-id=${component.id}]`);
      if (componentSpecificationTag) {

How can this be falsey for a React on Rails component?


Comments from Reviewable

@hchevalier
Copy link
Contributor Author

Review status: 10 of 15 files reviewed at latest revision, 2 unresolved discussions.


spec/dummy/client/app/startup/clientRegistration.jsx, line 4 at r3 (raw file):

Previously, justin808 (Justin Gordon) wrote…

Any explanation for the addition of these?

I think we should use something like this for all of these:

Done.


spec/dummy/client/app/components/HelloWorldRehydratable.jsx, line 47 at r3 (raw file):

Previously, justin808 (Justin Gordon) wrote…

How can this be falsey for a React on Rails component?

Done.


Comments from Reviewable

@justin808
Copy link
Member

Just one thing I see...


Review status: all files reviewed at latest revision, all discussions resolved.


spec/dummy/client/webpack.client.base.config.js, line 73 at r4 (raw file):

          {
            loader: 'expose-loader',
            options: '$'

Why do we need to use $ for jQuery in example? I don't like it, as it the $ is used for ES6 string interpolation.

If you just want to let others know about this option, you can add a comment to the line above for jQuery to create a similar entry to expose $ if your rails JS code needs $ exposed globally.


Comments from Reviewable

@justin808
Copy link
Member

:lgtm:


Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@justin808
Copy link
Member

Review status: all files reviewed at latest revision, 1 unresolved discussion.


README.md, line 545 at r5 (raw file):

  Note: client hydration will not trigger for components rendered through XHR. You will have to handle it with javascript.
  For an example, see [spec/dummy/app/views/pages/xhr_refresh.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/pages/xhr_refresh.rb). 

Are you sure this link works? This will be done from the README.md so it might not.


spec/dummy/client/app/components/HelloWorldRehydratable.jsx, line 43 at r5 (raw file):

    const match = document.querySelectorAll(`[id^=${registeredComponentName}-react-component-]`);
    // Not all browsers support forEach on NodeList so we go with a classic for-loop
    for (let i = 0; i < match.length; i += 1) {

The


Comments from Reviewable

@justin808 justin808 merged commit 047f229 into shakacode:master Jun 1, 2018
@justin808
Copy link
Member

Thanks @hchevalier!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants