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

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

Merged
merged 3 commits into from
Jan 8, 2025

Conversation

edison1105
Copy link
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
Copy link

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
9 of 11 checks passed
@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
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.

2 participants