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(reactivity): ensure unref correctly resolves type for ShallowRef #11360

Merged
merged 4 commits into from
Jul 17, 2024

Conversation

jh-leong
Copy link
Member

close #11356

  • Updated MaybeRef type to include ShallowRef in ref.ts.

Copy link

github-actions bot commented Jul 15, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 89.6 kB 34.2 kB 30.9 kB
vue.global.prod.js 146 kB 53.7 kB 47.9 kB

Usages

Name Size Gzip Brotli
createApp 49.6 kB 19.5 kB 17.8 kB
createSSRApp 53 kB 20.9 kB 19 kB
defineCustomElement 51.9 kB 20.2 kB 18.4 kB
overall 63.1 kB 24.5 kB 22.2 kB

@jh-leong
Copy link
Member Author

Could someone please run the ecosystem-cI? Thanks!

@edison1105
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented Jul 15, 2024

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools failure failure
nuxt success success
pinia success success
primevue success success
quasar success success
radix-vue success success
router success success
test-utils success success
vant success success
vite-plugin-vue success success
vitepress success success
vue-i18n success success
vue-macros success success
vuetify success success
vueuse failure success
vue-simple-compiler success success

@jh-leong
Copy link
Member Author

The vueuse build failed in ecosystem-ci because vueuse maintains its own definitions of MaybeRef and MaybeRefOrGetter, and there are mixed uses of locally defined types and types imported from vue-demi, leading to type compatibility issues.

I fixed this issue in PR #4099.

@yyx990803
Copy link
Member

yyx990803 commented Jul 15, 2024

A similar issue was fixed for ComputedRef<T> in #8748

I think the fix should be consistent to make MaybeRef<T> also include ComputedRef<T> (and remove ComputedRef<T> from unref's argument union)

@jh-leong
Copy link
Member Author

A similar issue was fixed for ComputedRef<T> in #8748.

I think the fix should be consistent to make MaybeRef<T> also include ComputedRef<T> and remove ComputedRef<T> from unref's argument union.

According to the test case below, MaybeRef seems to be writable (ref this comment):

describe('toRef <-> toValue', () => {
function foo(
a: MaybeRef<string>,
b: () => string,
c: MaybeRefOrGetter<string>,
d: ComputedRef<string>,
) {
const r = toRef(a)
expectType<Ref<string>>(r)
// writable
r.value = 'foo'

Should we change this behavior?

@yyx990803
Copy link
Member

In this case changing MaybeRef seems to technically be a type-level breaking change, and we should only do it in 3.5.

For now the immediate fix for #11356 should be just adding ShallowRef to the unref argument union.

@jh-leong
Copy link
Member Author

jh-leong commented Jul 16, 2024

In this case changing MaybeRef seems to technically be a type-level breaking change, and we should only do it in 3.5.

For now the immediate fix for #11356 should be just adding ShallowRef to the unref argument union.

Updated.

Based on you feedback, would it be reasonable to submit a PR to the minor branch with the following fix (this will not break the existing test)?

export type MaybeRef<T = any> = T | Ref<T> | ShallowRef<T> | WritableComputedRef<T>
export type MaybeRefOrGetter<T = any> = MaybeRef<T> | (() => T)

@yyx990803
Copy link
Member

Based on you feedback, would it be reasonable to submit a PR to the minor branch with the following fix

Yes please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

return type of unref includes ShallowRef if the passed type is ShallowRef | ComputedRef | MaybeRef
4 participants