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

Use data attrs when rendering react_components instead of script tags #113

Merged
merged 3 commits into from
Nov 22, 2015

Conversation

justin808
Copy link
Member

See discussion at #102.

ryanaip and others added 3 commits November 21, 2015 21:59
Client side rendering scripts do not get called when using the forward/back buttons with turbolinks, because turbolinks does not re-evaluate script tags when navigating through the history.

Instead of creating script tags throughout the page, instead use html elements with data attributes specifying each react component to be rendered, and iterate through all of those elements whenever the page loads.

This has the added benefit of removing global data variables from being set on the window object and simplifying the rendering code.

(Note that it will be possible to support turbolinks navigation with the still-on-master `data-turbolinks-eval=always` feature of turbolinks.  But this solution doesn't depend on that upgrade and is a bit cleaner anyway.)
Because that is to prevent XSS when JS is put in HTML.
* Avoid any chance of conflicts with a user desired class name.
* Set display:none on the div with data for the react component. This
  should prevent the browser from having any rendering issues from the
  extra div.
@justin808
Copy link
Member Author

@ryanaip @alexfedoseev I'm going to go with Ryan's changes for now. There's too many concerns with the next version of TurboLinks to depend on TurboLinks eval'ing the script tag. I tested out the Rails 5 version and it's not there right now, and v3 will probably never be released.

@justin808 justin808 changed the title Ryanaip data tags with a few additional changes Use data attrs when rendering react_components instead of script tags Nov 22, 2015
justin808 added a commit that referenced this pull request Nov 22, 2015
Use data attrs when rendering react_components instead of script tags
@justin808 justin808 merged commit 4f5c51b into master Nov 22, 2015
@justin808 justin808 deleted the ryanaip-data-tags branch November 22, 2015 08:25
@justin808
Copy link
Member Author

@ryanaip Big thanks for this fix.

@ryanaip
Copy link
Contributor

ryanaip commented Nov 22, 2015

Looks good — Glad to help out!

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.

2 participants