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

test(effect): verify cleanupEffect clears multiple dependencies #9503

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

jh-leong
Copy link
Member

Add a new test case to validate the cleanupEffect function when clearing multiple dependencies, extending test coverage beyond single dependencies.

Closes #5541.

@github-actions
Copy link

github-actions bot commented Oct 30, 2023

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 86.5 kB 32.9 kB 29.7 kB
vue.global.prod.js 132 kB 49.6 kB 44.5 kB

Usages

Name Size Gzip Brotli
createApp 48 kB 18.9 kB 17.2 kB
createSSRApp 51.2 kB 20.2 kB 18.4 kB
defineCustomElement 50.4 kB 19.7 kB 17.9 kB
overall 61.4 kB 23.7 kB 21.6 kB

@jh-leong jh-leong changed the title test(effect): verify cleanupEffect clears multiple dependencies (#5541) test(effect): verify cleanupEffect clears multiple dependencies Oct 30, 2023
@haoqunjiang haoqunjiang added the 🧹 p1-chore Priority 1: this doesn't change code behavior. label Oct 31, 2023
@skirtles-code
Copy link
Contributor

The test added here looks good to me.

This test was originally written to test this code:

function cleanupEffect(effect: ReactiveEffect) {
const { deps } = effect
if (deps.length) {
for (let i = 0; i < deps.length; i++) {
deps[i].delete(effect)
}
deps.length = 0
}
}

As explained in #5541, the existing tests all passed if the for loop was removed and replaced with code that just cleans up the first item in the array. In other words, nothing tests that the loop actually loops.

I've confirmed that this test does indeed fix the problem as originally described.

However...

Since this test was created, effect.ts has been rewritten. I'm not sure there's an equivalent loop in the new code. The closest I could find was this loop:

function postCleanupEffect(effect: ReactiveEffect) {
if (effect.deps.length > effect._depsLength) {
for (let i = effect._depsLength; i < effect.deps.length; i++) {
cleanupDepEffect(effect.deps[i], effect)
}
effect.deps.length = effect._depsLength
}
}

But if I make similar changes to that loop, so that it doesn't actually loop, this test doesn't catch that mistake. I haven't dug down in enough detail to figure out why.

That said, maybe that doesn't matter. The test itself makes sense and it does catch potential problems that the existing tests aren't testing.

@yyx990803 yyx990803 merged commit d04417d into vuejs:main Jun 6, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 p1-chore Priority 1: this doesn't change code behavior.
Projects
Development

Successfully merging this pull request may close these issues.

cleanupEffect missing edge test case
4 participants