-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
fix(runtime-core): invalidating jobs with duplicates #7745
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
Conversation
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
Size ReportBundles
Usages
|
It only logs twice for now, maybe that already fixed via some commits. |
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
Good point. I did some digging... this is a bit difficult to explain, but I'll try my best.
The reactivity system improvements in 3.4 are hiding the issue in my original example. The wrong job gets invalidated, but it gets away with it because the component doesn't actually end up rendering.
core/packages/runtime-core/src/renderer.ts Line 1291 in cf8cd1d
So the only way to hit core/packages/runtime-core/src/renderer.ts Lines 1585 to 1589 in cf8cd1d
This is why my original example no longer renders 3 times, because the This raises another question: do we actually need to invalidate the update job in the first place? If the So, in summary...
|
@skirtles-code |
The scheduler queue can contain duplicates of the same job in some circumstances, i.e. if the job gets added again while the queue is flushing, after it has already run the first time.
invalidateJob()
currently doesn't take account of that, just searching for the first index:This could be fixed using
lastIndexOf()
, but instead I've added a start index to theindexOf()
call. This should be sufficient, as a job should only appear once in the unprocessed part of the queue.Adding an index should theoretically make the
indexOf()
a bit faster, though in practice it's unlikely to matter.The incorrect invalidation logic can lead to components being rendered unnecessarily. In practice this is quite difficult to hit in real code, as it takes some quite specific circumstances for
invalidateJob()
to be called with duplicate jobs in the queue:SFC Playground
In the example above, clicking the button logs
Child rendering
3 times, when it should just be logged twice.The same example with this PR:
SFC Playground - Fixed