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(runtime-core): unwatch should be callable during SSR #11925

Merged
merged 2 commits into from
Sep 16, 2024

Conversation

deleteme
Copy link
Contributor

@deleteme deleteme commented Sep 13, 2024

Fixes the unwatch is not a function TypeError reported in #11924.

fix #11924

Copy link

github-actions bot commented Sep 13, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB 37.9 kB 34.1 kB
vue.global.prod.js 159 kB 57.8 kB 51.4 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 48.8 kB 18.8 kB 17.2 kB
createApp 55.4 kB (+25 B) 21.3 kB (+3 B) 19.4 kB (-62 B)
createSSRApp 59.4 kB (+25 B) 23 kB (-2 B) 21 kB (+40 B)
defineCustomElement 60.2 kB (+25 B) 22.8 kB 20.8 kB (-6 B)
overall 69.1 kB (+25 B) 26.4 kB (+3 B) 24 kB (+21 B)

Copy link

pkg-pr-new bot commented Sep 13, 2024

Open in Stackblitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@11925

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@11925

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@11925

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@11925

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@11925

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@11925

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@11925

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@11925

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@11925

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@11925

vue

pnpm add https://pkg.pr.new/vue@11925

commit: 3d993ec

@@ -9,6 +9,7 @@ declare var __ESM_BUNDLER__: boolean
declare var __ESM_BROWSER__: boolean
declare var __CJS__: boolean
declare var __SSR__: boolean
declare var __VUE_SSR_SETTERS__: Array<(v: boolean) => void>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added to address TypeScript type check errors in the test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if it's undesirable to declare __VUE_SSR_SETTERS__. Maybe that exposes this type and it's not intended to be public. If so, is there a better way to type that interface in the unit test?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can export setInSSRSetupState and import it into apiWatch.spec.ts using a relative path.

let setInSSRSetupState: (state: boolean) => void

__VUE_SSR_SETTERS__.forEach((setInSSRSetupState: SetBoolean) => {
setInSSRSetupState(ssr)
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This exists to hit the SSR code path that has the regression.

watchStopHandle.stop = NOOP
watchStopHandle.resume = NOOP
watchStopHandle.pause = NOOP
return watchStopHandle
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered doing this:

return Object.assign(() => {}, {
  stop: NOOP,
  resume: NOOP,
  pause: NOOP,
})

But decided against it to avoid the temporary allocation of the object literal.

@edison1105 edison1105 added scope: ssr regression 🐞 bug Something isn't working ❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. labels Sep 14, 2024
@yyx990803
Copy link
Member

The better way to test the SSR code path is to actually render the component with @vue/server-renderer, so I refactored the test to use that. This also avoids the global types issue.

@yyx990803 yyx990803 merged commit 2d6adf7 into vuejs:main Sep 16, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working regression scope: ssr
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vue 3.5 $watch doesn't return a function during SSR
3 participants