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

Projects
None yet
3 participants
@mfo
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot 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.

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 from Hi, to StreamingTemplateRenderer fails to forward I18n.locale in layouts Aug 22, 2017

@mfo

This comment has been minimized.

Show comment
Hide comment
@mfo

mfo Aug 25, 2017

Contributor

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 :

Contributor

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 :

@eileencodes

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

fix(streaming_template_renderer): I18n.locale broken in layout. I18n …
…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

This comment has been minimized.

Show comment
Hide comment
@mfo

mfo Nov 25, 2017

Contributor

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. 👍

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@mfo

mfo Nov 27, 2017

Contributor

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 .
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@mfo

mfo Dec 11, 2017

Contributor

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

Contributor

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

continuous-integration/travis-ci/pr The Travis CI build failed
Details
codeclimate All good!
Details
@eileencodes

This comment has been minimized.

Show comment
Hide comment
@eileencodes

eileencodes Dec 11, 2017

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@mfo

mfo Dec 15, 2017

Contributor

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

Contributor

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