Skip to content

fix(reactivity): ensure multiple effectScope on() and off() calls maintains correct active scope#12641

Merged
yyx990803 merged 3 commits intovaporfrom
edison/fix/effectScope
Jan 8, 2025
Merged

fix(reactivity): ensure multiple effectScope on() and off() calls maintains correct active scope#12641
yyx990803 merged 3 commits intovaporfrom
edison/fix/effectScope

Conversation

@edison1105
Copy link
Copy Markdown
Member

@edison1105 edison1105 commented Jan 3, 2025

The following code does not work correctly in the current vapor branch. When the button is clicked, the button text does not update.

<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>

<template>
  <button id="btn" @click="count++">{{ count }}</button>
  <div v-if="count < 1">{{ count }}</div>
  <div v-else>{{ count * 2 }}</div>
</template>

The issue is because scope.on is called twice:

if scope equals i.scope the following happens

scope1.on()  // activeEffectScope = scope1, prevScope = undefined
scope1.on()  // activeEffectScope = scope1, prevScope = scope1 (❌)
scope1.off() // activeEffectScope = scope1 (❌)
scope1.off() // activeEffectScope = undefined

The core also has a similar issue, see #12631. It is also caused by scope.on() being called multiple times. I have already created a PR #12632 to fix it. The changes in #12632 aim to avoid redundant updates to currentInstance, while this PR supports multiple calls to on. If this PR is merged, #12632 will no longer be needed.

@edison1105 edison1105 added the scope: vapor related to vapor mode label Jan 3, 2025
@edison1105 edison1105 changed the title feat(effectScope): allow multiple calls by tracking call count feat(effectScope): allow multiple on() calls by tracking call count Jan 3, 2025
@netlify
Copy link
Copy Markdown

netlify bot commented Jan 8, 2025

Deploy Preview for vapor-repl ready!

Name Link
🔨 Latest commit 499af49
🔍 Latest deploy log https://app.netlify.com/sites/vapor-repl/deploys/677e4d2e7c9312000877b740
😎 Deploy Preview https://deploy-preview-12641--vapor-repl.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@yyx990803 yyx990803 merged commit 679cbdf into vapor Jan 8, 2025
@yyx990803 yyx990803 deleted the edison/fix/effectScope branch January 8, 2025 10:03
@yyx990803 yyx990803 changed the title feat(effectScope): allow multiple on() calls by tracking call count fix(reactivity): ensure multiple effectScope on() and off() calls maintains correct active scope Jan 8, 2025
yyx990803 added a commit that referenced this pull request Jan 8, 2025
…ntains correct active scope

close #12631
close #12632

This is a combination of changes from both 8dec243 and #12641
@edison1105
Copy link
Copy Markdown
Member Author

We need a minimal reproduction

@MirkoJa
Copy link
Copy Markdown

MirkoJa commented Feb 10, 2026

Seems like i missed something when comparing the code between this change and vue 3.5.14. It looks identical and i noticed i missed that effectScope was completely refactored in the vapor branch. I will try once again to provide a reproduction. Do you have any tips for trying to produce the memory leak with effectScope?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: vapor related to vapor mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants