Skip to content

Commit 763faac

Browse files
committed
wip(ssr): revert reactivity ssr paths
The perf gains are not worth the correctness issues these paths may lead to
1 parent cc47ae0 commit 763faac

File tree

4 files changed

+8
-25
lines changed

4 files changed

+8
-25
lines changed

packages/reactivity/src/baseHandlers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export const readonlyHandlers: ProxyHandler<object> = {
165165
}
166166
}
167167

168-
// props handlers are special in the sense that it should not unwrap top-level
168+
// Props handlers are special in the sense that it should not unwrap top-level
169169
// refs (in order to allow refs to be explicitly passed down), but should
170170
// retain the reactivity of the normal readonly object.
171171
export const shallowReadonlyHandlers: ProxyHandler<object> = {

packages/reactivity/src/computed.ts

-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ export function computed<T>(
5656
// expose effect so computed can be stopped
5757
effect: runner,
5858
get value() {
59-
if (__SSR__) {
60-
return getter()
61-
}
62-
6359
if (dirty) {
6460
value = runner()
6561
dirty = false

packages/reactivity/src/reactive.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isObject, toRawType, EMPTY_OBJ } from '@vue/shared'
1+
import { isObject, toRawType } from '@vue/shared'
22
import {
33
mutableHandlers,
44
readonlyHandlers,
@@ -77,7 +77,8 @@ export function readonly<T extends object>(
7777

7878
// @internal
7979
// Return a reactive-copy of the original object, where only the root level
80-
// properties are readonly, and does not recursively convert returned properties.
80+
// properties are readonly, and does NOT unwrap refs nor recursively convert
81+
// returned properties.
8182
// This is used for creating the props proxy object for stateful components.
8283
export function shallowReadonly<T extends object>(
8384
target: T
@@ -117,15 +118,9 @@ function createReactiveObject(
117118
if (!canObserve(target)) {
118119
return target
119120
}
120-
const handlers = __SSR__
121-
? // disable reactivity in SSR.
122-
// NOTE: a potential caveat here is isReactive check may return different
123-
// values on nested values on client/server. This should be very rare but
124-
// we should keep an eye on this.
125-
EMPTY_OBJ
126-
: collectionTypes.has(target.constructor)
127-
? collectionHandlers
128-
: baseHandlers
121+
const handlers = collectionTypes.has(target.constructor)
122+
? collectionHandlers
123+
: baseHandlers
129124
observed = new Proxy(target, handlers)
130125
toProxy.set(target, observed)
131126
toRaw.set(observed, target)

packages/reactivity/src/ref.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ export function ref(value?: unknown) {
3636
return value
3737
}
3838
value = convert(value)
39-
40-
if (__SSR__) {
41-
return {
42-
_isRef: true,
43-
value
44-
}
45-
}
46-
4739
const r = {
4840
_isRef: true,
4941
get value() {
@@ -66,7 +58,7 @@ export function ref(value?: unknown) {
6658
export function toRefs<T extends object>(
6759
object: T
6860
): { [K in keyof T]: Ref<T[K]> } {
69-
if (__DEV__ && !__SSR__ && !isReactive(object)) {
61+
if (__DEV__ && !isReactive(object)) {
7062
console.warn(`toRefs() expects a reactive object but received a plain one.`)
7163
}
7264
const ret: any = {}

0 commit comments

Comments
 (0)