-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
feat(reactivity): untrack #13286
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
base: minor
Are you sure you want to change the base?
feat(reactivity): untrack #13286
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis change introduces a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Ref
participant ComputedRef
participant Effect
User->>Ref: a = ref(1)
User->>ComputedRef: c = computed(() => a.value + 1)
User->>Ref: a.peek()
Note right of Ref: Returns value without tracking
User->>ComputedRef: c.peek()
Note right of ComputedRef: Returns computed value without tracking
User->>Effect: effect(() => { untrack(() => a.value) })
Note right of Effect: Access inside untrack is not tracked
Suggested labels
Suggested reviewers
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@teleskop150750 |
@@ -284,6 +284,15 @@ export function cleanup( | |||
} | |||
} | |||
|
|||
export function untrack<T>(fn: () => T): T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we consider using MaybeRefOrGetter<T>
instead of () => T
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course you can. But the utility won't be too overloaded from this. ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just call toValue(source)
. In other words this will make it an untrack
wrapper around toValue
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand you perfectly. In my mindset, passing Ref directly should be almost completely avoided. Therefore, the use of toValue is minimized. If necessary, the user can call it himself inside untrack, rather than doing it automatically each time. If you insist, I will add your edit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is just my opinion. I think I would prefer to hear what others think.
RFC vuejs/rfcs#747
Implementation
Allows access without dependency tracking
Summary by CodeRabbit
New Features
peek()
method for refs and computed refs, allowing users to access current values without triggering reactivity.untrack
utility function to enable reading reactive values without establishing dependencies.Tests
peek()
method and theuntrack
utility, ensuring non-reactive access and correct caching behavior.