Skip to content

Commit

Permalink
fix: should to pre change dynamic slots
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleSound committed Apr 14, 2024
1 parent 6c99c7a commit 22c0538
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/runtime-vapor/src/componentSlots.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { type IfAny, isArray, isFunction } from '@vue/shared'
import {
type EffectScope,
ReactiveEffect,
type SchedulerJob,
SchedulerJobFlags,
effectScope,
isReactive,
shallowReactive,
Expand All @@ -13,6 +16,8 @@ import {
import { type Block, type Fragment, fragmentKey } from './apiRender'
import { renderEffect } from './renderEffect'
import { createComment, createTextNode, insert, remove } from './dom/element'
import { queueJob } from './scheduler'
import { VaporErrorCodes, callWithAsyncErrorHandling } from './errorHandling'

// TODO: SSR

Expand Down Expand Up @@ -51,8 +56,13 @@ export const initSlots = (
if (dynamicSlots) {
slots = shallowReactive(slots)
const dynamicSlotKeys: Record<string, true> = {}
renderEffect(() => {
const _dynamicSlots = dynamicSlots()

const effect = new ReactiveEffect(() => {
const _dynamicSlots = callWithAsyncErrorHandling(
dynamicSlots,
instance,
VaporErrorCodes.RENDER_FUNCTION,
)
for (let i = 0; i < _dynamicSlots.length; i++) {
const slot = _dynamicSlots[i]
// array of dynamic slot generated by <template v-for="..." #[...]>
Expand Down Expand Up @@ -88,6 +98,12 @@ export const initSlots = (
}
}
})

const job: SchedulerJob = () => effect.run()
job.flags! |= SchedulerJobFlags.PRE
job.id = instance.uid
effect.scheduler = () => queueJob(job)
effect.run()
}

instance.slots = slots
Expand Down

0 comments on commit 22c0538

Please sign in to comment.