You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fiber = Fiber.new do
if layout
layout.render(view, locals, output, &yielder)
else
# If you don't have a layout, just render the thing
# and concatenate the final result. This is the same
# as a layout with just <%= yield %>
output.safe_concat view._layout_for
end
end
Some parts of the stack rely on Thread.current[]... ex: the I18n which stores the current I18n config in Thread.current[:i18n_config].
the result is I18n(.locale, I18n.t, t(), ...) does not works within the layout (and all the call which rely on a Thread.current[]).
Expected behavior
You tell me.
A few ideas:
Instead of using a classic Fiber, use a custom one that copy the caller's I18n_config in its scope:
class FiberWithI18n < Fiber
def self.new_with(caller_i18n_config = I18n.config, &block)
new do
I18n.config = caller_i18n_config
block.call
end
end
end
Instead of using a classic Fiber, use a custom one that copy the caller's Thread.current[] in its scope:
class FiberWithLocalsFromCallerThread < Fiber
def self.new_with(caller_thread = Thread.current, &block)
caller_thread_locals = extract_thread_locals(caller_thread)
new do
reapply_locals(Thread.current, caller_thread_locals)
block.call
end
end
def self.extract_thread_locals(thread)
thread.keys.inject({}) do |memo, thread_local_varname|
memo[thread_local_varname] = thread[thread_local_varname]
memo
end
end
def self.reapply_locals(thread, locals)
locals.each_pair do|key, value|
thread[key] = value
end
end
end
Drop the Fiber (which is the root cause of this bug) and use a threaded model.
Actual behavior
Within the layout we loose all track of Thread.current[]
System configuration
Rails version: I tested with 5.1.3 Ruby version: I tested with 2.4.1p111
But I'm not sure it's relevant, Fiber does not support access to Thread.current, so same behaviour since the introduction of the Fiber.
The text was updated successfully, but these errors were encountered:
Ok maybe I'm simply wrong about the expected feature of the render stream :true. But I want to flush my response as earlier as possible (via a Transfer-Encoding: chunked).
Steps to reproduce
I have a waiting PR on this issue, but It's stalled. So I'm here to check if it's something you plan to support.
Here is some background :
render stream:true
is implemented via ActionView::StreamingTemplateRenderer. The layouts is rendered within a Fiber:But Fibers can't access Thread.current[]. ex:
Thread.current[:i18n_config]
.Expected behavior
You tell me.
A few ideas:
Actual behavior
Within the layout we loose all track of Thread.current[]
System configuration
Rails version: I tested with 5.1.3
Ruby version: I tested with 2.4.1p111
But I'm not sure it's relevant, Fiber does not support access to Thread.current, so same behaviour since the introduction of the Fiber.
The text was updated successfully, but these errors were encountered: