From 2a4670b8812abd46dddd96b797613431546cc38b Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sun, 27 Oct 2024 19:47:44 +0800 Subject: [PATCH 1/6] fix(types): should wrap the original type with `Reactive` in `DistributeRef` --- packages/reactivity/src/ref.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 6b8d541819d..09ae22ab7a3 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -8,6 +8,7 @@ import { import { Dep, getDepFromReactive } from './dep' import { type Builtin, + type Reactive, type ShallowReactiveMarker, isProxy, isReactive, @@ -489,7 +490,7 @@ export type ShallowUnwrapRef = { [K in keyof T]: DistributeRef } -type DistributeRef = T extends Ref ? V : T +type DistributeRef = T extends Ref ? Reactive : T export type UnwrapRef = T extends ShallowRef From e0a8508ccaad4f47357fc177ced885cb4650a4a2 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sun, 27 Oct 2024 21:35:11 +0800 Subject: [PATCH 2/6] fix: use `UnwrapNestedRefs` --- packages/reactivity/src/ref.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 09ae22ab7a3..3f73eca0216 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -8,8 +8,8 @@ import { import { Dep, getDepFromReactive } from './dep' import { type Builtin, - type Reactive, type ShallowReactiveMarker, + type UnwrapNestedRefs, isProxy, isReactive, isReadonly, @@ -490,7 +490,7 @@ export type ShallowUnwrapRef = { [K in keyof T]: DistributeRef } -type DistributeRef = T extends Ref ? Reactive : T +type DistributeRef = T extends Ref ? UnwrapNestedRefs : T export type UnwrapRef = T extends ShallowRef From 9a1f3b1a1199d3f0b230015f1c3df641a825298f Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 27 Oct 2024 13:36:07 +0000 Subject: [PATCH 3/6] [autofix.ci] apply automated fixes --- packages/reactivity/src/ref.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 3f73eca0216..9fd25c58820 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -490,7 +490,8 @@ export type ShallowUnwrapRef = { [K in keyof T]: DistributeRef } -type DistributeRef = T extends Ref ? UnwrapNestedRefs : T +type DistributeRef = + T extends Ref ? UnwrapNestedRefs : T export type UnwrapRef = T extends ShallowRef From 375a07dc83f6ffa2f11b5fa808717ff1c54e5db5 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sun, 27 Oct 2024 21:51:31 +0800 Subject: [PATCH 4/6] `UnwrapRef` under non-strict mode --- packages/reactivity/src/ref.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 9fd25c58820..1dc72a46df0 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -494,11 +494,13 @@ type DistributeRef = T extends Ref ? UnwrapNestedRefs : T export type UnwrapRef = - T extends ShallowRef - ? V - : T extends Ref - ? UnwrapRefSimple - : UnwrapRefSimple + T extends undefined + ? T + : T extends ShallowRef + ? V + : T extends Ref + ? UnwrapRefSimple + : UnwrapRefSimple export type UnwrapRefSimple = T extends | Builtin From a93d316cabd1da5dc14271bbc71d25c73fae8a79 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 27 Oct 2024 13:52:32 +0000 Subject: [PATCH 5/6] [autofix.ci] apply automated fixes --- packages/reactivity/src/ref.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 1dc72a46df0..cf7b4b154a2 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -493,14 +493,13 @@ export type ShallowUnwrapRef = { type DistributeRef = T extends Ref ? UnwrapNestedRefs : T -export type UnwrapRef = - T extends undefined - ? T - : T extends ShallowRef - ? V - : T extends Ref - ? UnwrapRefSimple - : UnwrapRefSimple +export type UnwrapRef = T extends undefined + ? T + : T extends ShallowRef + ? V + : T extends Ref + ? UnwrapRefSimple + : UnwrapRefSimple export type UnwrapRefSimple = T extends | Builtin From 021d1c6b9ae37423f9b5847844ab06d50131533b Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Wed, 30 Oct 2024 16:09:04 +0800 Subject: [PATCH 6/6] fix: use `ShallowReactive` --- packages/reactivity/src/index.ts | 1 + packages/reactivity/src/reactive.ts | 4 ++++ packages/reactivity/src/ref.ts | 8 ++++++-- packages/runtime-core/src/index.ts | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/reactivity/src/index.ts b/packages/reactivity/src/index.ts index f0445e87da0..7480bb2f9e3 100644 --- a/packages/reactivity/src/index.ts +++ b/packages/reactivity/src/index.ts @@ -36,6 +36,7 @@ export { type Raw, type DeepReadonly, type ShallowReactive, + type IsShallowReactive, type UnwrapNestedRefs, type Reactive, type ReactiveMarker, diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index 729c854965e..07e6c2f51ac 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -107,6 +107,10 @@ export declare const ShallowReactiveMarker: unique symbol export type ShallowReactive = T & { [ShallowReactiveMarker]?: true } +export type IsShallowReactive = T extends { [ShallowReactiveMarker]?: true } + ? true + : false + /** * Shallow version of {@link reactive()}. * diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index cf7b4b154a2..1addaf4ef9d 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -8,8 +8,8 @@ import { import { Dep, getDepFromReactive } from './dep' import { type Builtin, + type ShallowReactive, type ShallowReactiveMarker, - type UnwrapNestedRefs, isProxy, isReactive, isReadonly, @@ -491,7 +491,11 @@ export type ShallowUnwrapRef = { } type DistributeRef = - T extends Ref ? UnwrapNestedRefs : T + T extends Ref + ? V extends object + ? ShallowReactive + : V + : T export type UnwrapRef = T extends undefined ? T diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 3871167b3ee..0d71412fb97 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -210,6 +210,7 @@ export type { ReactiveFlags, DeepReadonly, ShallowReactive, + IsShallowReactive, UnwrapNestedRefs, ComputedRef, WritableComputedRef,