Move property mock logic to Twig compiler #42
Merged
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.
Resolves #41
New release 2.21 of UX Twig Components removes the ability to override
this
andcomputed
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.