Skip to content

Commit

Permalink
Added docs, changelog, better messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dzirtusss committed Dec 30, 2024
1 parent 313a40d commit ce763cc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Changes since the last non-beta release.
- Enables progressive page loading and improved performance for server-rendered React components
- Added support for replaying console logs that occur during server rendering of streamed React components. This enables debugging of server-side rendering issues by capturing and displaying console output on the client and on the server output. [PR #1647](https://github.com/shakacode/react_on_rails/pull/1647) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
- Added support for handling errors happening during server rendering of streamed React components. It handles errors that happen during the initial render and errors that happen inside suspense boundaries. [PR #1648](https://github.com/shakacode/react_on_rails/pull/1648) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
- Added support for passing options to `YAML.safe_load` when loading locale files with `config.i18n_yml_safe_load_options`. [PR #1668](https://github.com/shakacode/react_on_rails/pull/1668) by [dzirtusss](https://github.com/dzirtusss).

#### Changed
- Console replay script generation now awaits the render request promise before generating, allowing it to capture console logs from asynchronous operations. This requires using a version of the Node renderer that supports replaying async console logs. [PR #1649](https://github.com/shakacode/react_on_rails/pull/1649) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
Expand Down
3 changes: 3 additions & 0 deletions docs/guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ ReactOnRails.configure do |config|
# The default format is json
config.i18n_output_format = 'json'

# Possible YAML.safe_load options pass-through for locales
# config.i18n_yml_safe_load_options = { permitted_classes: [Symbol] }

################################################################################
################################################################################
# TEST CONFIGURATION OPTIONS
Expand Down
5 changes: 5 additions & 0 deletions docs/guides/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ You can use [Rails internationalization (i18n)](https://guides.rubyonrails.org/i
1) run the rake task to build the translations before running the lint command or
2) to run the tests first.
4. If your locale files (or one of the gems locale files) contains unsafe YAML, you may need to configure `config.i18n_yml_safe_load_options` if you can't fix such yamls properly.
```rb
config.i18n_yml_safe_load_options = { permitted_classes: [Symbol] }
```

By default, the locales are generated as JSON, but you can also generate them as JavaScript with [`react-intl`](https://formatjs.io/docs/getting-started/installation/) support:

1. Specify the i18n output format in `config/initializers/react_on_rails.rb`:
Expand Down
5 changes: 4 additions & 1 deletion lib/react_on_rails/locales/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ def generate_translations
translations = translations.deep_merge(key => val)
defaults = defaults.deep_merge(flatten_defaults(val)) if key == default_locale
rescue Psych::Exception => e
raise ReactOnRails::Error, "Error parsing #{f}: #{e.message}"
raise ReactOnRails::Error, <<~MSG
Error parsing #{f}: #{e.message}
Consider fixing unsafe YAML or permitting with config.i18n_yml_safe_load_options
MSG
end
[translations.to_json, defaults.to_json]
end
Expand Down
8 changes: 4 additions & 4 deletions spec/react_on_rails/locales_to_js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ module ReactOnRails
end

it "raises error with filename when not permitted" do
expect { described_class.new }.to raise_error(
ReactOnRails::Error,
"Error parsing #{locale_dir}/de.yml: Tried to load unspecified class: Symbol"
)
expect { described_class.new }.to raise_error(ReactOnRails::Error, <<~MSG)
Error parsing #{locale_dir}/de.yml: Tried to load unspecified class: Symbol
Consider fixing unsafe YAML or permitting with config.i18n_yml_safe_load_options
MSG
end
end
end
Expand Down

0 comments on commit ce763cc

Please sign in to comment.