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

Don't pretty format JSON in development #789

Merged
merged 3 commits into from
Apr 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]

## [Unreleased]

## [6.9.2] - 2017-04-02

### Changed
- Update version_checker.rb to `logger.error` rather than `logger.warn` for gem/npm version mismatch. [#788](https://github.com/shakacode/react_on_rails/issues/788) by [justin808](https://github.com/justin808).

### Fixed
- Remove pretty formatting of JSON in development. [#789](https://github.com/shakacode/react_on_rails/pull/789) by [justin808](https://github.com/justin808)
- Clear hydrated stores with each server rendered block. [#785](https://github.com/shakacode/react_on_rails/pull/785) by [udovenko](https://github.com/udovenko)

## [6.9.1] - 2017-03-30
Expand Down Expand Up @@ -515,7 +518,8 @@ Best done with Object destructing:
##### Fixed
- Fix several generator related issues.

[Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.9.1...master
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.9.2...master
[6.9.2]: https://github.com/shakacode/react_on_rails/compare/6.9.1...6.9.2
[6.9.1]: https://github.com/shakacode/react_on_rails/compare/6.8.2...6.9.1
[6.9.0]: https://github.com/shakacode/react_on_rails/compare/6.8.2...6.9.0
[6.8.2]: https://github.com/shakacode/react_on_rails/compare/6.8.1...6.8.2
Expand Down
23 changes: 13 additions & 10 deletions app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,19 @@ def server_render_js(js_expression, options = {})
private

def json_safe_and_pretty(hash_or_string)
if Rails.env.development?
# 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(hash_or_string.to_json)
end
# if Rails.env.development?
# # 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
#
# Temp fix given that a hash may contain active record objects and that crashed with the new
# code to JSON.pretty_generate
ERB::Util.json_escape(hash_or_string.to_json)
# end
end

# prepend the rails_context if not yet applied
Expand Down
11 changes: 7 additions & 4 deletions rakelib/dummy_apps.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ require_relative "task_helpers"
include ReactOnRails::TaskHelpers

namespace :dummy_apps do
task :dummy_app do
task :yarn_install do
yarn_install_cmd = "yarn install --mutex network && yarn run install-react-on-rails"
sh_in_dir(dummy_app_dir, yarn_install_cmd)
end

task dummy_app: [:yarn_install] do
dummy_app_dir = File.join(gem_root, "spec/dummy")
bundle_install_in(dummy_app_dir)
sh_in_dir(dummy_app_dir, "yarn install --mutex network")
end

task :dummy_app_with_turbolinks_2 do
task dummy_app_with_turbolinks_2: [:yarn_install] do
dummy_app_dir = File.join(gem_root, "spec/dummy")
bundle_install_with_turbolinks_2_in(dummy_app_dir)
sh_in_dir(dummy_app_dir, "yarn install --mutex network")
end

task dummy_apps: [:dummy_app, :node_package] do
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"build:dev:server": "webpack -w --config webpack.server.rails.build.config.js",
"build:server": "webpack --config webpack.server.rails.build.config.js",
"hot-assets": "babel-node server-rails-hot.js",
"install-react-on-rails": "npm i --save 'file:../../..'"
"install-react-on-rails": "rm -rf node_modules/react-on-rails && npm i 'file:../../..'"
Copy link
Contributor

Choose a reason for hiding this comment

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

does rm -rf return truthy here?

},
"author": "",
"license": "ISC"
Expand Down
5 changes: 1 addition & 4 deletions spec/dummy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,5 @@
"url": "https://github.com/shakacode/react_on_rails/issues"
},
"devDependencies": {},
"dependencies": {
"babel-cli": ">= 6",
"babel-runtime": ">= 6"
}
"dependencies": {}
}
Loading