Skip to content
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

Move property mock logic to Twig compiler #42

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

squrious
Copy link
Collaborator

@squrious squrious commented Nov 7, 2024

Resolves #41

New release 2.21 of UX Twig Components removes the ability to override this and computed keys in the component template context.

The mock system was built on top of this ability, so as stated in the linked issue it can not work anymore this way.

This PR moves the mock logic to the compile step instead. When compiling templates for Storybook, Twig will add a special node to all module nodes to change the context before starting to display the actual node content. It's quite rough but as we are in a dedicated Twig environment, I consider it acceptable.

Then, when Storybook renders a component, it adds some context variables to the component event (a Storybook context) so the context changes are triggered from the compiled template based on these variables.

If it works well with the tag component syntax (embedded), the function syntax still triggers the base component renderer, which actually uses the base Twig environment, not configured for Storybook. There is a quick fix for this here to provide a different implementation of the component runtime. I hope we'll find a more robust way to do this in the future.

@squrious squrious force-pushed the twig-component-2.21.0 branch 2 times, most recently from a7baca1 to fa8d8c0 Compare November 7, 2024 10:50
@squrious squrious force-pushed the twig-component-2.21.0 branch from fa8d8c0 to 73e675f Compare November 7, 2024 11:14
@squrious squrious marked this pull request as ready for review November 7, 2024 11:17
@squrious squrious requested a review from WebMamba November 7, 2024 11:19
@squrious squrious merged commit 8c0ca89 into sensiolabs:main Dec 10, 2024
8 checks passed
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.

Component mock doesn't work anymore
1 participant