Skip to content

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

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
Nov 6, 2024

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Oct 29, 2024

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

return new SetNode(false, new Nodes([$name]), new Nodes([$node->getNode('expr')]), $node->getTemplateLine());
}

$var = '__internal_trans_default_domain';

if (null !== $templateName = $node->getTemplateName()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what we do when there is no template name? We could use an internal counter in this visitor and append it to the prefix instead maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a counter can replace any hashing, then yes, that'd be nicer

return new SetNode(false, new Nodes([$name]), new Nodes([$node->getNode('expr')]), $node->getTemplateLine());
}

$var = '__internal_trans_default_domain_'.$this->nestingLevel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the implementation to rely on a counter instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas using a counter for the nesting level inside the current template does not solve the issue that this PR tries to fix, meaning that my comment in #57609 (comment) is not solved and that Symfony 7.2 still breaks the case where both a parent template and its child template use {% trans_default_domain %}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR, this was fixed in #58706

@nicolas-grekas nicolas-grekas merged commit 5557736 into symfony:7.2 Nov 6, 2024
10 checks passed
@nicolas-grekas
Copy link
Member

Thank you @xabbuh

@fabpot fabpot mentioned this pull request Nov 6, 2024
@xabbuh xabbuh deleted the pr-57609 branch November 6, 2024 10:04
if (class_exists(Nodes::class)) {
$name = new LocalVariable(null, $node->getTemplateLine());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xabbuh changing this to a local variable is likely the root cause of EasyCorp/EasyAdminBundle#6605 because a local variable will not be available in blocks (it won't stay available in the Twig child scopes that are totally separate PHP scopes in the compiled template).

To me, we should keep assigning a context variable, as done before your PR.

return new SetNode(false, new Nodes([$name]), new Nodes([$node->getNode('expr')]), $node->getTemplateLine());
}

$var = '__internal_trans_default_domain_'.$this->nestingLevel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas using a counter for the nesting level inside the current template does not solve the issue that this PR tries to fix, meaning that my comment in #57609 (comment) is not solved and that Symfony 7.2 still breaks the case where both a parent template and its child template use {% trans_default_domain %}

xabbuh added a commit that referenced this pull request Dec 2, 2024
This PR was merged into the 7.2 branch.

Discussion
----------

[TwigBridge] generate conflict-free variable names

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #58706 (comment), Fix EasyCorp/EasyAdminBundle#6605, Fix twigphp/Twig#4480
| License       | MIT

Commits
-------

1a38aca generate conflict-free variable names
symfony-splitter pushed a commit to symfony/twig-bridge that referenced this pull request Dec 2, 2024
This PR was merged into the 7.2 branch.

Discussion
----------

[TwigBridge] generate conflict-free variable names

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix symfony/symfony#58706 (comment), Fix EasyCorp/EasyAdminBundle#6605, Fix twigphp/Twig#4480
| License       | MIT

Commits
-------

1a38acac24 generate conflict-free variable names
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