Skip to content

Commit

Permalink
Fixes Crash in Development for String Props (shakacode#784)
Browse files Browse the repository at this point in the history
* Fixes Crash in Development for String Props

Bug caused by not handling JSON.pretty_generate for strings.

TODO:
1. Add test
2. Add error handler if cannot parse the string with nice
message
3. Consider checking that if not a string then a Hash
  • Loading branch information
justin808 authored Mar 31, 2017
1 parent 85a79c4 commit 99fc635
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 279 deletions.
11 changes: 8 additions & 3 deletions app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,16 @@ def server_render_js(js_expression, options = {})

private

def json_safe_and_pretty(something)
def json_safe_and_pretty(hash_or_string)
if Rails.env.development?
ERB::Util.json_escape(JSON.pretty_generate(something.as_json))
# TODO: for json_safe_and_pretty
# 1. Add test
# 2. Add error handler if cannot parse the string with nice message
# 3. Consider checking that if not a string then a Hash
hash_value = hash_or_string.is_a?(String) ? JSON.parse(hash_or_string) : hash_or_string
ERB::Util.json_escape(JSON.pretty_generate(hash_value))
else
ERB::Util.json_escape(something.to_json)
ERB::Util.json_escape(hash_or_string.to_json)
end
end

Expand Down
7 changes: 3 additions & 4 deletions spec/dummy/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,8 @@ GEM
thread_safe (0.3.6)
tilt (2.0.6)
tins (1.13.2)
turbolinks (5.0.1)
turbolinks-source (~> 5)
turbolinks-source (5.0.0)
turbolinks (2.5.3)
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (3.1.4)
Expand Down Expand Up @@ -322,7 +321,7 @@ DEPENDENCIES
selenium-webdriver
spring
sqlite3
turbolinks (~> 5.0)
turbolinks (= 2.5.3)
uglifier

BUNDLED WITH
Expand Down
43 changes: 25 additions & 18 deletions spec/dummy/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,6 @@ async@^2.1.2, async@^2.1.4, async@^2.1.5:
dependencies:
lodash "^4.14.0"

async@~0.2.6:
version "0.2.10"
resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1"

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
Expand Down Expand Up @@ -4115,7 +4111,7 @@ react-dom@^15.4.2:
object-assign "^4.1.0"

"react-on-rails@file:../../..":
version "6.8.0"
version "6.9.0"

react-proxy@^1.1.7:
version "1.1.8"
Expand Down Expand Up @@ -4619,6 +4615,10 @@ source-list-map@^0.1.7, source-list-map@~0.1.7:
version "0.1.8"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-0.1.8.tgz#c550b2ab5427f6b3f21f5afead88c4f5587b2106"

source-list-map@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-1.1.1.tgz#1a33ac210ca144d1e561f906ebccab5669ff4cb4"

source-map-resolve@^0.3.0:
version "0.3.1"
resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.3.1.tgz#610f6122a445b8dd51535a2a71b783dfc1248761"
Expand Down Expand Up @@ -4962,14 +4962,14 @@ ua-parser-js@^0.7.9:
version "0.7.12"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"

uglify-js@^2.7.5:
version "2.8.3"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.3.tgz#1ed5037bc224904c43d36e7310177c02c4c76808"
uglify-js@^2.8.5:
version "2.8.18"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.18.tgz#925d14bae48ab62d1883b41afe6e2261662adb8e"
dependencies:
async "~0.2.6"
source-map "~0.5.1"
uglify-to-browserify "~1.0.0"
yargs "~3.10.0"
optionalDependencies:
uglify-to-browserify "~1.0.0"

uglify-to-browserify@~1.0.0:
version "1.0.2"
Expand Down Expand Up @@ -5104,7 +5104,7 @@ warning@^3.0.0:
dependencies:
loose-envify "^1.0.0"

watchpack@^1.2.0:
watchpack@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.3.1.tgz#7d8693907b28ce6013e7f3610aa2a1acf07dad87"
dependencies:
Expand Down Expand Up @@ -5157,16 +5157,23 @@ webpack-dev-server@^2.4.1:
webpack-dev-middleware "^1.9.0"
yargs "^6.0.0"

webpack-sources@^0.1.0, webpack-sources@^0.1.4:
webpack-sources@^0.1.0:
version "0.1.4"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-0.1.4.tgz#ccc2c817e08e5fa393239412690bb481821393cd"
dependencies:
source-list-map "~0.1.7"
source-map "~0.5.3"

webpack@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-2.2.1.tgz#7bb1d72ae2087dd1a4af526afec15eed17dda475"
webpack-sources@^0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-0.2.3.tgz#17c62bfaf13c707f9d02c479e0dcdde8380697fb"
dependencies:
source-list-map "^1.1.1"
source-map "~0.5.3"

webpack@^2.3.1:
version "2.3.2"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-2.3.2.tgz#7d521e6f0777a3a58985c69425263fdfe977b458"
dependencies:
acorn "^4.0.4"
acorn-dynamic-import "^2.0.0"
Expand All @@ -5184,9 +5191,9 @@ webpack@^2.2.1:
source-map "^0.5.3"
supports-color "^3.1.0"
tapable "~0.2.5"
uglify-js "^2.7.5"
watchpack "^1.2.0"
webpack-sources "^0.1.4"
uglify-js "^2.8.5"
watchpack "^1.3.1"
webpack-sources "^0.2.3"
yargs "^6.0.0"

websocket-driver@>=0.5.1:
Expand Down
Loading

0 comments on commit 99fc635

Please sign in to comment.