Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(defineModel): detect changes respect custom getter and setter #11543

Merged
merged 8 commits into from
Aug 7, 2024

Conversation

liuseen-l
Copy link
Contributor

@liuseen-l liuseen-l commented Aug 7, 2024

resolve: #11541
resolve: #11526
related: #11527

This change can solve both problems #11541 and #11526 at the same time, but it is only for the sake of solving the problem. I think it needs to be fundamentally solved from the design point of view. The logic of haschange should judge the custom setter and getter together.

 set(value) {
  if (
    !hasChanged(options.set ? options.set(value) : value, options.get ? options.get(localValue) : localValue) &&
    !(prevSetValue !== EMPTY_OBJ && hasChanged(value, prevSetValue))
  ) {
    return
    }
     ....
}

If it is changed like this, then the phenomenon of #11526 It's not a problem, it's in line with expectations

Copy link

github-actions bot commented Aug 7, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 90.2 kB (-8.09 kB) 34.6 kB (-2.71 kB) 31.2 kB (-2.38 kB)
vue.global.prod.js 147 kB (-9.05 kB) 54.1 kB (-2.97 kB) 48.1 kB (-2.58 kB)

Usages

Name Size Gzip Brotli
createApp 49.7 kB (-4.29 kB) 19.5 kB (-1.43 kB) 17.8 kB (-1.31 kB)
createSSRApp 53.2 kB (-4.64 kB) 21 kB (-1.56 kB) 19.1 kB (-1.41 kB)
defineCustomElement 51.9 kB (-6.61 kB) 20.2 kB (-2.15 kB) 18.5 kB (-1.9 kB)
overall 63.2 kB (-4.34 kB) 24.5 kB (-1.45 kB) 22.3 kB (-1.32 kB)

@liuseen-l liuseen-l changed the title fix: useModel change logic fix(defineModel): detect changes respect custom getter and setter Aug 7, 2024
@edison1105
Copy link
Member

The logic of haschange should judge the custom setter and getter together.

I think the logic that determines whether a change is made cannot use emittedValue, it should use the value passed in.
#11526 should not be a bug.

@edison1105 edison1105 added the need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. label Aug 7, 2024
@yyx990803
Copy link
Member

For #11526 the to-be-emitted value is different from parent state, so it should indeed emit. It also worked in versions < 3.4.31 so we should keep it working.

@yyx990803 yyx990803 merged commit e042888 into vuejs:main Aug 7, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.
Projects
None yet
3 participants