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

ues ref on dom element will not trigger watch or watchEffect #2456

Closed
Jokcy opened this issue Oct 22, 2020 · 5 comments
Closed

ues ref on dom element will not trigger watch or watchEffect #2456

Jokcy opened this issue Oct 22, 2020 · 5 comments

Comments

@Jokcy
Copy link
Contributor

Jokcy commented Oct 22, 2020

Version

3.0.2

Reproduction link

https://jsfiddle.net/h8k7rp45/1/

Steps to reproduce

just click the text Hello Vuejs, then look at the console, it will output undefined once, then after 1 second, output hehe0. If I remove the setTimeout, the hehe0 will never output

What is expected?

output hehe0 when CompA mounted

What is actually happening?

not output hehe0 when CompA mounted


it mainly because watch & watchEffect push preJobs, and ref.value = element worked at queue jobs (the middle), when push preJobs, it's still flushing, so it will not flush again. And after postEffects, no queue jobs and postEffects add, it won't run preJobs again.

@Jokcy
Copy link
Contributor Author

Jokcy commented Oct 22, 2020

is there any side effects if we flushJobs when pendingPreFlushCbs.length > 0

if (queue.length || pendingPostFlushCbs.length || pendingPreFlushCbs.length) {
      flushJobs(seen)
    }

this code passed all test

@HcySunYang
Copy link
Member

Do this:

watchEffect(() => ..., { flush: 'post' })

@Jokcy
Copy link
Contributor Author

Jokcy commented Oct 22, 2020

Do this:

watchEffect(() => ..., { flush: 'post' })

Yeah, I know, but the implemention is confusing so it still need to talk if this is as expected or not.

@posva
Copy link
Member

posva commented Oct 22, 2020

@posva posva closed this as completed Oct 22, 2020
@Jokcy
Copy link
Contributor Author

Jokcy commented Oct 22, 2020

@posva
I did not find one issue that exactly match mine, besides, can you just give me an answer?
Is this by design?
So it mean if I want to use ref to attach dom element I have to use flush: post to watch it right?
I don't quite understand why you guys so eager to close issues.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants