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

this.$forceUpdate changes #5556

Closed
DellCliff opened this issue Mar 9, 2022 · 1 comment
Closed

this.$forceUpdate changes #5556

DellCliff opened this issue Mar 9, 2022 · 1 comment
Labels
✨ feature request New feature or request

Comments

@DellCliff
Copy link

Version

3.2.31

Reproduction link

sfc.vuejs.org/

Steps to reproduce

let beforeMountForceUpdate;
let beforeUnmountForceUpdate;

beforeMount() {
beforeMountForceUpdate = this.$forceUpdate;
listenable.addEventListener("change", this.$forceUpdate);
},

beforeUnmount() {
beforeUnmountForceUpdate = this.$forceUpdate;
console.log(beforeMountForceUpdate === beforeUnmountForceUpdate);
listenable.removeEventListener("change", this.$forceUpdate);
}

What is expected?

beforeMountForceUpdate === beforeUnmountForceUpdate

What is actually happening?

beforeMountForceUpdate !== beforeUnmountForceUpdate


Results in memory leaks.

@zscumt123
Copy link
Contributor

in Lifecycle Hooks, 'this' is proxy, eg.

const fnObj = {
// return a function
  $forceUpdate: () => () => console.log('fn')
}
const obj = {}
const proxy = new Proxy(obj, {
  get(target, key) {
    if (fnObj[key]) {
      return fnObj[key]()
    }
    return undefined
  }
})
let fn1 = proxy.$forceUpdate
let fn2 = proxy.$forceUpdate
console.log(fn1 === fn2) //false

@LinusBorg LinusBorg added the ✨ feature request New feature or request label Mar 10, 2022
iwusong pushed a commit to iwusong/core that referenced this issue May 13, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Sep 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✨ feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants