Repository navigation
Conversation
…nders The hookable context was dropped when dehydrating the HookableMetadata LiveProp, so the component template, its nested hooks and their conditions saw an empty context during live re-renders. - getDehydratedHookableContextKeys(): opt-in list of scalar context values kept in the LiveProp - provideHookableContext(): values (objects included) given back by the component at render time - HookableMetadata::withContext()
loic425
added a commit
to loic425/Sylius
that referenced
this pull request
Nov 2, 2026
The live grid component gives the grid view, the resource metadata, the live flag and the active criteria back to its hookables with provideHookableContext() (Sylius/Stack#400), so the template does not have to pass them again to the "grid" hook. Requires the twig-hooks-live-context branch of Sylius/Stack (not released yet).
loic425
marked this pull request as ready for review
November 2, 2026 14:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
HookableLiveComponentTraitdehydrates thehookableMetadataLiveProp to the hook name, the configuration and the prefixes only. On a live re-render, the hookable context is empty:hookable_metadata.context.*is empty in the component template;{% hook %}calls don't get the parent context;conditions and@=expressions of the nested hookables see an empty_context.The context can't simply be serialized into the LiveProp: it usually holds objects (grid views, resource metadata, entities, forms), which are too large for the payload and must not be readable by the client.
Solution
Two overridable methods on the trait. Both do nothing by default, so there's no BC break, and the payload only changes when a component lists keys:
provideHookableContext()is applied at render time, on the first render and on every re-render, through#[ExposeInTemplate(getter: ...)]. It runs after the live actions, and its values are never dehydrated. Use it to give back objects built from the component's own LiveProps.getDehydratedHookableContextKeys()keeps plain values in the LiveProp. The LiveProp isn't writable, so the checksum covers them. Values that aren't scalars, nulls or arrays of them throw aLogicException.HookableMetadata::withContext().Example, from the Sylius admin live grid (Sylius/Sylius#19289):
With this, the component template goes from
{% hook 'grid' with { resources: grid, metadata, live_grid: true, are_criteria_set: this.hasActiveCriteria() } %}to{% hook 'grid' %}.Notes
DataBagHydrationExtension(unregistered) is left untouched: it would dehydrate the whole bag, objects included.InteractsWithLiveComponents. That's whysymfony/browser-kitandsymfony/css-selectorare added to the Twig Hooksrequire-dev; the rootcomposer.jsonalready has both.