Skip to content

[TwigBridge]  Use constant var name to cache trans_default_domain expression result #57609

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

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jun 30, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? no
Deprecations? no
Issues Part of #57588
License MIT

When trans_default_domain is used with an expression, the result of the expression is cached into a variable and this variable is stored in the Scope to be used for each following usage of the |trans filter.

This var name doesn't need to be random:

  • there is only 1 value in the scope, more than 1 variable at a time is never necessary.
  • if trans_default_domain is called a second time, the same variable can be reassigned.

The only benefit of using a random var name would be to prevent usage in the template. The name __internal_trans_default_domain self-explains that it is not meant to be used.

@carsonbot carsonbot changed the title [TwigBridge] Use constant var name to cache trans_default_domain expression result [TwigBridge]  Use constant var name to cache trans_default_domain expression result Jun 30, 2024
@carsonbot carsonbot added this to the 7.2 milestone Jun 30, 2024
@fabpot
Copy link
Member

fabpot commented Jul 1, 2024

Thank you @GromNaN.

@fabpot fabpot merged commit 68a5704 into symfony:7.2 Jul 1, 2024
9 of 10 checks passed
@GromNaN GromNaN deleted the twig-uniqid-trans branch July 1, 2024 17:07
@stof
Copy link
Member

stof commented Oct 25, 2024

Using a fixed variable name is actually broken. The Twig scope is shared with all the inheritance tree of templates, so we do have multiple names per scope (as {% trans_default_domain %} is meant to apply only to the current template)

Kocal pushed a commit to Kocal/symfony that referenced this pull request Feb 13, 2025
… default domain node visitor (xabbuh)

This PR was merged into the 7.2 branch.

Discussion
----------

[TwigBridge] use reproducible variable names in the default domain node visitor

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | Fix symfony#57609 (comment)
| License       | MIT

Commits
-------

500d72f use reproducible variable names in the default domain node visitor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants