Skip to content

Commit d6b496c

Browse files
committed
chore: minor tweaks
1 parent 9d443d4 commit d6b496c

File tree

3 files changed

+72
-75
lines changed

3 files changed

+72
-75
lines changed

packages/runtime-vapor/__tests__/components/Teleport.spec.ts

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
setInsertionState,
1717
setText,
1818
template,
19-
useVaporCssVars,
2019
vaporInteropPlugin,
2120
withVaporDirectives,
2221
} from '@vue/runtime-vapor'
@@ -27,7 +26,6 @@ import {
2726
onBeforeUnmount,
2827
onMounted,
2928
onUnmounted,
30-
reactive,
3129
ref,
3230
shallowRef,
3331
} from 'vue'
@@ -1331,67 +1329,4 @@ function runSharedTests(deferMode: boolean): void {
13311329
expect(target.innerHTML).toBe('content')
13321330
app.unmount()
13331331
})
1334-
1335-
test('with css vars', async () => {
1336-
const state = reactive({ color: 'red' })
1337-
const target = document.createElement('div')
1338-
document.body.appendChild(target)
1339-
1340-
const value = ref(true)
1341-
const Child = defineVaporComponent({
1342-
setup(_, { slots }) {
1343-
return slots.default!()
1344-
},
1345-
})
1346-
1347-
const Comp = defineVaporComponent({
1348-
setup() {
1349-
const t = createComponent(Child, null, {
1350-
default: () => {
1351-
return createComponent(Child, null, {
1352-
default: () => {
1353-
return createIf(
1354-
() => value.value,
1355-
() => {
1356-
return template('<div></div>')()
1357-
},
1358-
() => {
1359-
return template('<span></span>')()
1360-
},
1361-
)
1362-
},
1363-
})
1364-
},
1365-
})
1366-
1367-
return t
1368-
},
1369-
})
1370-
1371-
define({
1372-
setup() {
1373-
useVaporCssVars(() => state)
1374-
const n1 = createComponent(
1375-
VaporTeleport,
1376-
{ to: () => target },
1377-
{
1378-
default: () => createComponent(Comp),
1379-
},
1380-
)
1381-
return [n1]
1382-
},
1383-
}).render()
1384-
1385-
await nextTick()
1386-
for (const c of [].slice.call(target.children as any)) {
1387-
expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe(`red`)
1388-
expect((c as HTMLElement).outerHTML.includes('data-v-owner')).toBe(true)
1389-
}
1390-
value.value = false
1391-
await nextTick()
1392-
for (const c of [].slice.call(target.children as any)) {
1393-
expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe(`red`)
1394-
expect((c as HTMLElement).outerHTML.includes('data-v-owner')).toBe(true)
1395-
}
1396-
})
13971332
}

packages/runtime-vapor/__tests__/helpers/useCssVars.spec.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,68 @@ describe('useVaporCssVars', () => {
297297
expect(host.children[0].outerHTML.includes('data-v-owner')).toBe(true)
298298
})
299299

300+
test('with teleport and nested component', async () => {
301+
const state = reactive({ color: 'red' })
302+
const target = document.createElement('div')
303+
document.body.appendChild(target)
304+
305+
const value = ref(true)
306+
const Child = defineVaporComponent({
307+
setup(_, { slots }) {
308+
return slots.default!()
309+
},
310+
})
311+
312+
const Comp = defineVaporComponent({
313+
setup() {
314+
return createComponent(Child, null, {
315+
default: () => {
316+
return createComponent(Child, null, {
317+
default: () => {
318+
return createIf(
319+
() => value.value,
320+
() => {
321+
return template('<div></div>')()
322+
},
323+
() => {
324+
return template('<span></span>')()
325+
},
326+
)
327+
},
328+
})
329+
},
330+
})
331+
},
332+
})
333+
334+
define({
335+
setup() {
336+
useVaporCssVars(() => state)
337+
const n1 = createComponent(
338+
VaporTeleport,
339+
{ to: () => target },
340+
{
341+
default: () => createComponent(Comp),
342+
},
343+
)
344+
return n1
345+
},
346+
}).render()
347+
348+
await nextTick()
349+
let el = target.children[0] as HTMLElement
350+
expect(el.tagName).toBe('DIV')
351+
expect(el.outerHTML.includes('data-v-owner')).toBe(true)
352+
expect(el.style.getPropertyValue(`--color`)).toBe('red')
353+
354+
value.value = false
355+
await nextTick()
356+
el = target.children[0] as HTMLElement
357+
expect(el.tagName).toBe('SPAN')
358+
expect(el.outerHTML.includes('data-v-owner')).toBe(true)
359+
expect(el.style.getPropertyValue(`--color`)).toBe('red')
360+
})
361+
300362
test('with string style', async () => {
301363
const state = reactive({ color: 'red' })
302364
const root = document.createElement('div')

packages/runtime-vapor/src/components/Teleport.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ export class TeleportFragment extends VaporFragment {
108108
)
109109
})
110110
const nodes = this.nodes
111-
// register updateCssVars to root fragments's update hooks so that
111+
112+
// register updateCssVars to nested fragments's update hooks so that
112113
// it will be called when root fragment changed
113114
if (this.parentComponent && this.parentComponent.ut) {
114115
this.registerUpdateCssVars(nodes)
@@ -125,17 +126,16 @@ export class TeleportFragment extends VaporFragment {
125126
}
126127
}
127128

128-
private registerUpdateCssVars(nodes: Block) {
129-
if (isFragment(nodes)) {
130-
;(nodes.onUpdated || (nodes.onUpdated = [])).push(() =>
129+
private registerUpdateCssVars(block: Block) {
130+
if (isFragment(block)) {
131+
;(block.onUpdated || (block.onUpdated = [])).push(() =>
131132
updateCssVars(this),
132133
)
133-
this.registerUpdateCssVars(nodes.nodes)
134-
} else if (isVaporComponent(nodes)) {
135-
;(nodes.u || (nodes.u = [])).push(() => updateCssVars(this))
136-
this.registerUpdateCssVars(nodes.block)
137-
} else if (isArray(nodes)) {
138-
nodes.forEach(node => this.registerUpdateCssVars(node))
134+
this.registerUpdateCssVars(block.nodes)
135+
} else if (isVaporComponent(block)) {
136+
this.registerUpdateCssVars(block.block)
137+
} else if (isArray(block)) {
138+
block.forEach(node => this.registerUpdateCssVars(node))
139139
}
140140
}
141141

0 commit comments

Comments
 (0)