Fix outlet matching for whitespace-separated data-controller values - #911
Open
tchiadeu wants to merge 1 commit into
Open
Fix outlet matching for whitespace-separated data-controller values#911tchiadeu wants to merge 1 commit into
tchiadeu wants to merge 1 commit into
Conversation
…oller values
OutletSet#matchesElement tokenized the controller attribute with a
naive `.split(" ")`, only splitting on a single literal space
character. When a data-controller attribute is written across
multiple lines (e.g. generated by server-side templates that format
the value with newlines and indentation), each identifier except the
first ends up with trailing whitespace glued to it, so it never
equals the plain identifier and the outlet lookup silently fails to
find an otherwise correctly connected controller.
TokenListObserver already parses data-controller robustly via
`.trim().split(/\s+/)`. Apply the same tokenization in
OutletSet#matchesElement so outlet resolution is consistent with how
controllers are actually connected.
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.
OutletSet#matchesElementtokenizes thedata-controllerattribute with a naive.split(" "), splitting only on single literal space characters:When a
data-controllervalue is written across multiple lines, for example, generated by a server-side template that formats the attribute with newlines and indentation for readability, every identifier after the first ends up with a trailing newline glued to it ("my-controller\n"instead of"my-controller")..split(" ")never removes that newline, so.includes(outletName)returnsfalseeven though the controller is genuinely connected to that element. The result is a "Missing outlet element" error for an outlet that's actually present.This is inconsistent with how Stimulus parses
data-controllereverywhere else.TokenListObserver(responsible for actually connecting controllers) already handles this correctly via.trim().split(/\s+/). This PR applies the same tokenization inOutletSet#matchesElementso outlet resolution matches controller-connection semantics.Also adds a regression test reproducing a
data-controllervalue split across multiple lines, verifying the outlet is still found.