Skip to content

fix(reactivity): add __v_skip flag to Dep to prevent reactive conversion #12804

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

Merged
merged 6 commits into from
Jun 5, 2025

Conversation

serkodev
Copy link
Contributor

@serkodev serkodev commented Feb 2, 2025

Fix #12803

This PR adds dep to isNonTrackableKeys so that the readonly proxy does not convert dep to a readonly value, allowing it to be triggered by triggerRef.

Summary by CodeRabbit

  • Tests

    • Added a new test to verify manual triggering of effects on readonly shallowRefs using explicit triggers.
  • Chores

    • Introduced an internal property for improved handling within the system; no impact on end-user functionality.

Copy link

github-actions bot commented Feb 2, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (+17 B) 38.3 kB (+5 B) 34.6 kB (+25 B)
vue.global.prod.js 159 kB (+17 B) 58.5 kB (+5 B) 52.1 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB (+17 B) 18.2 kB (+5 B) 16.7 kB (+1 B)
createApp 54.6 kB (+17 B) 21.2 kB (+7 B) 19.4 kB (-4 B)
createSSRApp 58.8 kB (+17 B) 23 kB (+6 B) 21 kB (+3 B)
defineCustomElement 59.5 kB (+17 B) 22.8 kB (+4 B) 20.8 kB (+4 B)
overall 68.7 kB (+17 B) 26.4 kB (+5 B) 24 kB (+18 B)

Copy link

pkg-pr-new bot commented Feb 2, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@12804

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@12804

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@12804

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@12804

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@12804

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@12804

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@12804

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@12804

@vue/shared

npm i https://pkg.pr.new/@vue/shared@12804

vue

npm i https://pkg.pr.new/vue@12804

@vue/compat

npm i https://pkg.pr.new/@vue/compat@12804

commit: 171e9c4

@edison1105 edison1105 added 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. wait changes labels Feb 3, 2025
@edison1105 edison1105 added ready to merge The PR is ready to be merged. and removed wait changes labels Feb 3, 2025
@edison1105
Copy link
Member

LGTM

@edison1105 edison1105 changed the title fix: readonly ref able to trigger by triggerRef fix(reactivity): readonly ref able to trigger by triggerRef Feb 3, 2025
Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using __v_skip looks like a good approach to me.

The test is outside the describe section, it should probably be moved inside.

The PR description also needs updating to reflect the latest code.

Co-authored-by: skirtle <65301168+skirtles-code@users.noreply.github.com>
Copy link

coderabbitai bot commented May 30, 2025

Walkthrough

A new test case was added to the readonly reactivity test suite to verify that effects can be manually triggered on a readonly shallowRef using triggerRef. Additionally, a new internal readonly property __v_skip was introduced to the Dep class in the reactivity source code.

Changes

File(s) Change Summary
packages/reactivity/tests/readonly.spec.ts Added a test case for manually triggering effects on readonly shallowRef using triggerRef.
packages/reactivity/src/dep.ts Added internal readonly property __v_skip: true to the Dep class with a JSDoc and TODO note.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Case
    participant Ref as shallowRef (original)
    participant Readonly as readonly(shallowRef)
    participant Effect as Effect

    Test->>Ref: Create shallowRef({ n: 1 })
    Test->>Readonly: Wrap with readonly
    Test->>Effect: Setup effect tracking Readonly.value.n
    Test->>Ref: Mutate Ref.value.n++
    Effect-->>Test: No update triggered
    Test->>Readonly: triggerRef(Readonly)
    Effect-->>Test: Effect re-runs and observes updated value
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure triggerRef can trigger effects on a readonly ref (#12803)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation

Suggested labels

scope: reactivity

Poem

In the warren of code, a test hops anew,
Readonly refs now trigger, as all rabbits knew.
A skip flag was added—so sly and discreet,
Ensuring reactivity is robust and neat.
With a twitch of the nose and a hop in the grass,
This patch helps your signals update and pass! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22f359b and 4f28b45.

📒 Files selected for processing (2)
  • packages/reactivity/__tests__/readonly.spec.ts (2 hunks)
  • packages/reactivity/src/dep.ts (1 hunks)
🔇 Additional comments (3)
packages/reactivity/src/dep.ts (1)

96-100: LGTM: Skip marker addition aligns with PR objectives.

The addition of the __v_skip property correctly implements the fix to prevent readonly proxy conversion of the dep property, enabling proper triggerRef functionality on readonly refs.

Note that the TODO comment indicates this is a temporary implementation pending isolatedDeclarations support.

packages/reactivity/__tests__/readonly.spec.ts (2)

11-13: LGTM: Required imports correctly added.

The shallowRef and triggerRef imports are necessary for the new test case and are properly placed in the existing import structure.


526-537: Excellent test coverage for the triggerRef fix.

This test comprehensively validates the PR's objective by:

  • Creating a readonly wrapper around a shallowRef
  • Verifying that direct mutations don't trigger effects (expected behavior)
  • Confirming that triggerRef can properly trigger effects on readonly refs

The test correctly uses shallowRef instead of regular ref, which is essential for demonstrating this specific behavior where nested property changes don't automatically trigger effects.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@edison1105 edison1105 changed the title fix(reactivity): readonly ref able to trigger by triggerRef fix(reactivity): add __v_skip flag to Dep to prevent reactive conversion Jun 5, 2025
@edison1105
Copy link
Member

/ecosystem-ci run

@vuejs vuejs deleted a comment from edison1105 Jun 5, 2025
@vue-bot
Copy link
Contributor

vue-bot commented Jun 5, 2025

📝 Ran ecosystem CI: Open

suite result latest scheduled
quasar success success
primevue success success
language-tools success success
nuxt success success
vitepress success success
pinia success success
test-utils success success
router success success
vant success success
vite-plugin-vue success success
vuetify success success
vue-i18n success success
radix-vue success success
vue-macros failure success
vueuse success success
vue-simple-compiler success success

@edison1105 edison1105 merged commit e8d8f5f into vuejs:main Jun 5, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Readonly Ref cannot be triggered by triggerRef
4 participants