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

StreamingTemplateRenderer fails to forward I18n.locale in layouts #30361

Merged
merged 1 commit into from Dec 11, 2017

Conversation

@mfo
Copy link
Contributor

@mfo mfo commented Aug 22, 2017

Hello,

I recently used the option render stream: true to render some actions ( Ruby 2.4.1p111 / Rails 5.1.3 )

We noticed that our layout failed to keep the current locale [I18n.locale]. After some explorations, here is what happens :

  • the I18n gems stores the current config in a Thread.current[:local]
  • the StreamingTemplateRenderer streams the response via a Fiber.resume pattern
  • unfortunatelly the Fiber does not keeps the Thread.current[:i18n_config]

This commit includes a simple fix: keeping a reference of the I18n.config above the Fiber scope and re-applying this reference to I18n.config.

Here is a link to a gist (https://gist.github.com/mfo/e8e5d51fe52f6cacd33ea778b1ef6c6d) with other options :

  • FiberWithI18n -> copy the I18n.config from caller
  • FiberWithLocalsFromCallerThread -> copy all caller's threads local vars within the Fiber locals hash [it's a bit overkill but it may be useful for other gems/parts of rails]
  • you can switch implementations from the gist (and fails the test using normal Fiber class)
@rails-bot
Copy link

@rails-bot rails-bot commented Aug 22, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@mfo mfo changed the title Hi, StreamingTemplateRenderer fails to forward I18n.locale in layouts Aug 22, 2017
@mfo
Copy link
Contributor Author

@mfo mfo commented Aug 25, 2017

Maybe you are in holiday and in this case I wish you the best :-)

In case I missed something and it's a pain to deal with this issue, here is a simple rails app which reproduces this bug with a dedicated test : https://github.com/mfo/rails_30361
involved files :

Copy link
Member

@eileencodes eileencodes left a comment

Hey @mfo sorry for the delay on merging this. I think this looks good. Can you squash your commits into 1 single commit? Thanks!

@mfo mfo force-pushed the mfo:master branch Nov 25, 2017
…gem stores the current locale in Thread.current[:local] (see: https://github.com/svenfuchs/i18n/blob/master/lib/i18n.rb#L23). StreamingTemplateRenderer is implemented with Fiber which have its own stack of locals and can not access Thread.current.locals(keys, see: https://ruby-doc.org/core-2.2.0/Thread.html#class-Thread-label-Fiber-local+vs.+Thread-local).
@mfo mfo force-pushed the mfo:master branch to 6d3b57f Nov 25, 2017
@mfo
Copy link
Contributor Author

@mfo mfo commented Nov 25, 2017

I assumed you ran out of coffee : no worries for the delay ;-) It's squashed & up to date with rails/master. Thanks for your work. 👍

@mfo mfo closed this Nov 26, 2017
@mfo mfo reopened this Nov 26, 2017
@mfo mfo closed this Nov 27, 2017
@mfo mfo reopened this Nov 27, 2017
@mfo
Copy link
Contributor Author

@mfo mfo commented Nov 27, 2017

Sorry I'm closing/reopening this PR to relaunch the CI which failed on some apt-get :

apt-get install failed
The command "sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install ffmpeg mupdf mupdf-tools" failed and exited with 100 during .
@mfo mfo closed this Dec 11, 2017
@mfo mfo reopened this Dec 11, 2017
@mfo
Copy link
Contributor Author

@mfo mfo commented Dec 11, 2017

again I'm trying to pass the tests which sometimes fails and sometimes succeed ; let me know if I can help :-)

@eileencodes eileencodes merged commit 4edce56 into rails:master Dec 11, 2017
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
codeclimate All good!
Details
@eileencodes
Copy link
Member

@eileencodes eileencodes commented Dec 11, 2017

The failures aren't related to your branch so I merged. Sorry for the delay with this. Appreciate your time and patience! 😄

@mfo
Copy link
Contributor Author

@mfo mfo commented Dec 15, 2017

Thanks for your work Eileen and no worry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.