Skip to content

Fix i18n scope for nested lambda-backed slots#2633

Open
artinboghosian wants to merge 2 commits into
ViewComponent:mainfrom
artinboghosian:nested-lambda-slot-i18n-scope
Open

Fix i18n scope for nested lambda-backed slots#2633
artinboghosian wants to merge 2 commits into
ViewComponent:mainfrom
artinboghosian:nested-lambda-slot-i18n-scope

Conversation

@artinboghosian
Copy link
Copy Markdown

What are you trying to accomplish?

Fix relative t(".key") translations inside nested lambda-backed slots resolving against the wrong scope. Instead of resolving to the partial where the block was defined, they resolved to an intermediate component's virtual path.
Fixes the bug reported in #2513 which persisted after #2520.

What approach did you choose and why?

PR #2520 introduced __vc_content_block_virtual_path — capturing the virtual path at block-definition time and restoring it at block-evaluation time. This correctly fixed non-lambda slots via Slot#to_s.

However, lambda-backed slots are evaluated immediately inside __vc_set_slot rather than deferred to Slot#to_s. The lambda branch was updated in #2520 to wrap the block evaluation with with_captured_virtual_path, but used @old_virtual_path (the intermediate parent component's path) instead of the already-captured slot.__vc_content_block_virtual_path (the original partial's path).

The existing slot.__vc_content_block_virtual_path is defined via attr_writer, making it write-only. Rather than exposing it through an attr_reader, the captured path is stored in a local variable within __vc_set_slot and passed directly to the lambda branch. Happy to use a different approach if the project prefers exposing the reader instead.

@artinboghosian
Copy link
Copy Markdown
Author

@joelhawksley The failing check is also failing on main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant