Add shouldStopAtNode callback to closestDataStack#4734
Closed
joshhanley wants to merge 1 commit intoalpinejs:mainfrom
Closed
Add shouldStopAtNode callback to closestDataStack#4734joshhanley wants to merge 1 commit intoalpinejs:mainfrom
shouldStopAtNode callback to closestDataStack#4734joshhanley wants to merge 1 commit intoalpinejs:mainfrom
Conversation
Allows callers to stop scope collection at a specific node when traversing up the DOM tree.
Collaborator
|
change this to undefined callback plus conditional |
Collaborator
Author
|
Closed as we decided not to add the change to Livewire for now, that required this PR. |
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.
The Scenario
When Livewire contextualises
wire:clickexpressions, it prefixes bare identifiers with$wire.so they resolve against the component. For example,wire:click="$js.select(user)"becomes$wire.$js.select($wire.user).To support Alpine-scoped variables (like
x-foriteration items), Livewire needs to check Alpine's scope chain before prefixing. However,closestDataStacktraverses all the way up the DOM tree, which means Alpine scope from outside the Livewire component can incorrectly override$wireproperties.The Problem
There's currently no way to tell
closestDataStackwhere to stop collecting scope. It always traverses to the root of the document.The Solution
Add an optional
shouldStopAtNodecallback parameter toclosestDataStack. When provided, the function stops traversing and returns an empty array ifshouldStopAtNode(node)returnstrue.This allows Livewire to collect Alpine scope only within the component boundary.