From: underfin <2218301630@qq.com> Date: Tue, 28 Jul 2020 19:30:18 +0000 (+0800) Subject: fix(style-vars): fix css vars on component with suspense as root (#1718) X-Git-Tag: v3.0.0-rc.5~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07ece2e9260fe30a50e7cf317d2ff69f113ecad1;p=thirdparty%2Fvuejs%2Fcore.git fix(style-vars): fix css vars on component with suspense as root (#1718) --- diff --git a/packages/runtime-dom/__tests__/helpers/useCssVars.spec.ts b/packages/runtime-dom/__tests__/helpers/useCssVars.spec.ts index 5260d2a82b..293dc70499 100644 --- a/packages/runtime-dom/__tests__/helpers/useCssVars.spec.ts +++ b/packages/runtime-dom/__tests__/helpers/useCssVars.spec.ts @@ -4,7 +4,8 @@ import { h, reactive, nextTick, - ComponentOptions + ComponentOptions, + Suspense } from '@vue/runtime-dom' describe('useCssVars', () => { @@ -68,6 +69,48 @@ describe('useCssVars', () => { })) }) + test('on suspense root', async () => { + const state = reactive({ color: 'red' }) + const root = document.createElement('div') + + const AsyncComp = { + async setup() { + return () => h('p', 'default') + } + } + + const App = { + setup() { + useCssVars(() => state) + return () => + h(Suspense, null, { + default: h(AsyncComp), + fallback: h('div', 'fallback') + }) + } + } + + render(h(App), root) + // css vars use with fallback tree + for (const c of [].slice.call(root.children as any)) { + expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe(`red`) + } + // AsyncComp resolve + await nextTick() + // Suspense effects flush + await nextTick() + // css vars use with default tree + for (const c of [].slice.call(root.children as any)) { + expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe(`red`) + } + + state.color = 'green' + await nextTick() + for (const c of [].slice.call(root.children as any)) { + expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe('green') + } + }) + test('with