Repository navigation
Support rendering components in non-main Ractors - #2732
Open
joelhawksley wants to merge 4 commits into
Open
joelhawksley wants to merge 4 commits into
joelhawksley wants to merge 4 commits into
Conversation
Make ViewComponent compatible with Rails' experimental Rails.application.ractorize!: - Define generated render and slot methods with Ractor-shareable procs. - Make the compile cache shareable (copy-on-write under a lock). - Freeze class-level state read while rendering (identifier, virtual path, ancestor calls, i18n scope) and stop reading the compiler and class variables on the render path. - Share registered slots and sidecar i18n backends in a before_ractorize hook. - Don't capture preview options in the routes prepend block. - Add an isolated test that ractorizes a production app and renders components in non-main Ractors when supported. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9fa9df75-8ce8-4ebf-89d8-a06669026a8f
Pin the rails-main appraisals to Rails, Rack, and i18n revisions that support Rails.application.ractorize! (i18n: ruby-i18n/i18n#741), and fail rather than skip the Ractor test in the rails_main_head job. - Prime I18n.default_separator before ractorizing, since i18n memoizes it in a class ivar that non-main Ractors can't set. - Support Rails main's TemplateDetails::Requested in MissingTemplateError. - Prefer I18n.reserved_keys over the deprecated I18n::RESERVED_KEYS. - Pin rspec-rails to main for frozen default_url_options support. - Update Rails main allocation counts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9fa9df75-8ce8-4ebf-89d8-a06669026a8f
- Route compiled template rendering through an instance helper so @current_template is assigned on the component, not lexically in a class method. - Annotate CompileCache's shareable cache and lock with justification. - Make controller action_methods shareable in the Ractor test, avoiding a Ruby head VM crash until Rails does this in before_ractorize. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9fa9df75-8ce8-4ebf-89d8-a06669026a8f
Recent Ruby head aborts when a non-main Ractor reads a frozen Set that isn't marked shareable, and no longer lets Rails compile ActionView templates lazily inside Ractors. Share Rails' leftover frozen state after ractorize! and render the slots/collection/content cases through wrapper components instead of view templates. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9fa9df75-8ce8-4ebf-89d8-a06669026a8f
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #2728. Makes compiled components render in non-main Ractors under Rails' experimental
Rails.application.ractorize!.Changes
render_template_forand slot methods withRactor.make_shareableprocs. Fall back to the plain block when a user-supplied block captures unshareable state.CompileCachea shareable, copy-on-write set guarded by a lock.identifier,virtual_path, ancestor calls, and the i18n scope. Stop reading@__vc_compilerand class variables on the render path.before_ractorizehook that sharesregistered_slotsand the sidecar i18n backends. It also primesI18n.default_separator, which i18n memoizes in a class ivar that non-main Ractors can't set.optionsin the routesprependblock. That closure blockedractorize!at boot.test/isolated/ractor_test.rb, which boots a production app, callsractorize!, and renders components in Ractors: templates, inlinecall, variants, inheritance, slots, collections, content and translations. It skips when the prerequisites are missing, except in therails_main_headjob, where it fails instead.CI / dependencies
rails-mainandrails-main_headappraisals:7a569bca9833c8Shopify/i18n@58aa1dc, from Ractor support ruby-i18n/i18n#741main, which has an unreleased fix for frozendefault_url_optionsMissingTemplateErrorhandlesTemplateDetails::Requested, which no longer exposeslocale,formats,variantsorhandlers.I18n.reserved_keysinstead of the deprecatedI18n::RESERVED_KEYS.auditionrequires Ruby 4.0.Notes
@@fallbacksclass variable, which non-main Ractors can't read on 4.0. It passes on Ruby head..ractorize!to the sandbox app. It permanently freezes the app, and Rails only supports it in production, while the sandbox runs in test mode.