fix(defineModel): support kebab-case/camelCase mismatches #9950
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.
This PR attempts to fix a problem with the logic for detecting local mode. The problem occurs when the parent uses kebab-case and the child uses camelCase.
Here's an example illustrating the problem I'm trying to fix with 3.4.3:
The value is supposed to be restricted to the range 0-10, but clicking the buttons allows the child to drift out of that range.
This is because the parent uses
v-model:foo-bar
, with a hyphenated prop name, whereas the child is usingdefineModel('fooBar')
. It incorrectly uses local mode in that scenario.The example above works correctly if it is changed to
v-model:fooBar
instead, but that isn't an option if the parent uses an in-DOM template. Attempting to work around the problem in the child usingdefineModel('foo-bar')
results in an error. This PR does not address that error, it just tries to allow the parent template to use kebab-case.The key change is to check for
hyphenatedName in rawProps
. I've also added a check for`onUpdate:${hyphenatedName}` in rawProps
, though that is less important as the template compiler doesn't generate kebab-case listener names. I still thought it was worth including, both for consistency and because listeners can be passed in other ways without going through the compiler.Here's the same example above, but using this PR: