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

refactor(reactivity): remove computed SSR-specific code #10354

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ export class ComputedRefImpl<T> {
public readonly __v_isRef = true
public readonly [ReactiveFlags.IS_READONLY]: boolean = false

public _cacheable: boolean

constructor(
getter: ComputedGetter<T>,
private readonly _setter: ComputedSetter<T>,
isReadonly: boolean,
isSSR: boolean,
) {
this.effect = new ReactiveEffect(
() => getter(this._value),
Expand All @@ -58,16 +55,14 @@ export class ComputedRefImpl<T> {
: DirtyLevels.MaybeDirty,
),
)
this.effect.computed = this
this.effect.active = this._cacheable = !isSSR
this[ReactiveFlags.IS_READONLY] = isReadonly
}

get value() {
// the computed ref may get wrapped by other proxies e.g. readonly() #3376
const self = toRaw(this)
if (
(!self._cacheable || self.effect.dirty) &&
self.effect.dirty &&
hasChanged(self._value, (self._value = self.effect.run()!))
) {
triggerRefValue(self, DirtyLevels.Dirty)
Expand Down Expand Up @@ -139,7 +134,6 @@ export function computed<T>(
export function computed<T>(
getterOrOptions: ComputedGetter<T> | WritableComputedOptions<T>,
debugOptions?: DebuggerOptions,
isSSR = false,
) {
let getter: ComputedGetter<T>
let setter: ComputedSetter<T>
Expand All @@ -157,9 +151,9 @@ export function computed<T>(
setter = getterOrOptions.set
}

const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR)
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter)

if (__DEV__ && debugOptions && !isSSR) {
if (__DEV__ && debugOptions) {
cRef.effect.onTrack = debugOptions.onTrack
cRef.effect.onTrigger = debugOptions.onTrigger
}
Expand Down
5 changes: 0 additions & 5 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ export class ReactiveEffect<T = any> {
active = true
deps: Dep[] = []

/**
* Can be attached after creation
* @internal
*/
computed?: ComputedRefImpl<T>
/**
* @internal
*/
Expand Down
10 changes: 0 additions & 10 deletions packages/runtime-core/src/apiComputed.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
isPromise,
isString,
} from '@vue/shared'
import { type Ref, isRef } from '@vue/reactivity'
import { computed } from './apiComputed'
import { type Ref, computed, isRef } from '@vue/reactivity'
import {
type WatchCallback,
type WatchOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export const version = __VERSION__
export {
// core
computed,
reactive,
ref,
readonly,
Expand Down Expand Up @@ -35,7 +36,6 @@ export {
getCurrentScope,
onScopeDispose,
} from '@vue/reactivity'
export { computed } from './apiComputed'
export {
watch,
watchEffect,
Expand Down
9 changes: 0 additions & 9 deletions packages/server-renderer/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ function renderComponentSubTree(
comp.ssrRender = ssrCompile(comp.template, instance)
}

// perf: enable caching of computed getters during render
// since there cannot be state mutations during render.
for (const e of instance.scope.effects) {
if (e.computed) {
e.computed._dirty = true
e.computed._cacheable = true
}
}

const ssrRender = instance.ssrRender || comp.ssrRender
if (ssrRender) {
// optimized
Expand Down
Loading