GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [TwigHooks] Keep the hookable context of live components across re-renders by loic425 · Pull Request #400 · Sylius/Stack Conversation
Member
Problem
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. SolutionTwo 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: /** @return array<string> scalars, nulls or arrays of them; sent to the client */ protected function getDehydratedHookableContextKeys(): array { return []; } /** @return array<string, mixed> merged on top of the hookable context at render time */ protected function provideHookableContext(): array { return []; }
Example, from the Sylius admin live grid (Sylius/Sylius#19289): protected function provideHookableContext(): array { return [ 'resources' => $this->getGridView(), 'metadata' => $this->getMetadata(), 'live_grid' => true, 'are_criteria_set' => $this->hasActiveCriteria(), ]; } With this, the component template goes from Notes
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…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
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |