-
-
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
Change div tags to script tags and put viewContext/props inside #412
Comments
I'm working on a PR right now to address this. |
Turbo links is the tough one if we do that. Script tag is how I originally had it. Other issue is escaping the data. |
What issues does this cause with TurboLinks? If the data is put into the script tag as proper JSON what issue's might we still have? |
The page scripts don't run with TurboLinks, without some special configuration, and I'm not even sure on that. So TurboLinks will just insert the HTML tags on the existing page (so CSS and JS are not reloaded), and we have a hook from TurboLinks to parse the special dom elements and kick start the React parts. See https://github.com/turbolinks/turbolinks#working-with-script-elements |
According to the link
So that should be ok. The JSON on one of our largest menu pages is about 1mb as a string (JSON.stringify). We still have a number of people who access the menu on mobile devices instead our our apps so we need to make sure we can keep the page size as small as possible. |
Let's try it out! It's possible that the older turbo links didn't. |
I'll try to do some work on this over the weekend. I'm headed back to On Wed, May 4, 2016 at 5:34 PM, Justin Gordon [email protected]
|
@martyphee Any info on this? Be particularly careful with escaping issues. I.e., suppose you have application data sent in the JavasScript, and it can close the script tag and open a new one. |
I'll try to take a look at this today. On Fri, May 20, 2016 at 8:05 PM, Justin Gordon [email protected]
|
I got some work done on it, but haven't finished. On Sat, May 21, 2016 at 11:58 AM, Martin Phee [email protected] wrote:
|
@martyphee sounds like a great improvement. Is the difference noticeable on phone load time? |
@jbhatab I have most of the test passing now. I'll hopefully get the rest done in today or tomorrow. Mainly the ones which just check the rendering of the |
Ok, down to two test failures. |
@martyphee The most important thing is that we super, super carefully consider the escaping and that we have good tests. If we incorrectly put the data in the generated JavaScript, this would allow for script injection hack. |
Won't that be more of the server making sure it doesn't except or removes all XSS attempts? Not sure the best way of escaping the data on the server without causing other side effects. |
@justin808: just in case: http://apidock.com/rails/ERB/Util/json_escape properly escapes JSON-encoded strings for further inclusion to HTML code (inside the tags). It handles things like You can have a code like this:
and use it in your ERB template like this:
|
Hey Guys, I have a project I would love to use this on but we have a hard requirement of not being able to mount our state into the hidden divs the way this project does.. Has there been any progress on this or is there any way I can jump in and give a hand? |
@gregoryStarr it would be awesome to get your help. Both @martyphee and I would appreciate it. Please see the full message thread above. The main hazard is an XSS injection in the data. |
@gregoryStarr Please work off of #411. |
Closed by #775. |
On pages with large amounts of data the time to usability is dramatically increased on lower bandwidth connections as megabytes of html encoded JSON needs to be downloaded before the HTML that displays the page can be retrieved.
The text was updated successfully, but these errors were encountered: