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

fix(ssr): ensure computed only run once during render #9688

Merged
merged 1 commit into from
Dec 1, 2023
Merged
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
1 change: 0 additions & 1 deletion packages/server-renderer/__tests__/ssrComputed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ test('computed reactivity during SSR', async () => {
// In both cases we need to fetch data.
if (!msg.value) await store.fetchData()

expect(msg.value).toBe('hello world')
Copy link
Member Author

Choose a reason for hiding this comment

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

For the reasons for deleting this line, see #5300 (comment)

return () => h('div', null, msg.value + msg.value + msg.value)
})

Expand Down
5 changes: 4 additions & 1 deletion packages/server-renderer/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ function renderComponentSubTree(
// 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._cacheable = true
if (e.computed) {
e.computed._dirty = true
Copy link
Member Author

@edison1105 edison1105 Nov 28, 2023

Choose a reason for hiding this comment

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

Make sure that during ssrRender(), the computed is executed only once and then cached.

e.computed._cacheable = true
}
}

const ssrRender = instance.ssrRender || comp.ssrRender
Expand Down