|
@@ -63,7 +63,9 @@ function processDynamicChildren(context: TransformContext<ElementNode>) {
|
|
|
let staticCount = 0
|
|
let staticCount = 0
|
|
|
let dynamicCount = 0
|
|
let dynamicCount = 0
|
|
|
let lastInsertionChild: IRDynamicInfo | undefined
|
|
let lastInsertionChild: IRDynamicInfo | undefined
|
|
|
- const children = context.dynamic.children
|
|
|
|
|
|
|
+ const children = context.dynamic.children as (IRDynamicInfo & {
|
|
|
|
|
+ logicalIndex?: number
|
|
|
|
|
+ })[]
|
|
|
|
|
|
|
|
// Track logical index for each dynamic child
|
|
// Track logical index for each dynamic child
|
|
|
// logicalIndex represents the position in SSR DOM (counting fragments as single units)
|
|
// logicalIndex represents the position in SSR DOM (counting fragments as single units)
|
|
@@ -72,8 +74,7 @@ function processDynamicChildren(context: TransformContext<ElementNode>) {
|
|
|
for (const [index, child] of children.entries()) {
|
|
for (const [index, child] of children.entries()) {
|
|
|
if (child.flags & DynamicFlag.INSERT) {
|
|
if (child.flags & DynamicFlag.INSERT) {
|
|
|
// Assign logical index to this dynamic child
|
|
// Assign logical index to this dynamic child
|
|
|
- ;(child as IRDynamicInfo & { logicalIndex: number }).logicalIndex =
|
|
|
|
|
- currentLogicalIndex
|
|
|
|
|
|
|
+ child.logicalIndex = currentLogicalIndex
|
|
|
prevDynamics.push((lastInsertionChild = child))
|
|
prevDynamics.push((lastInsertionChild = child))
|
|
|
currentLogicalIndex++
|
|
currentLogicalIndex++
|
|
|
}
|
|
}
|
|
@@ -100,7 +101,7 @@ function processDynamicChildren(context: TransformContext<ElementNode>) {
|
|
|
registerInsertion(
|
|
registerInsertion(
|
|
|
prevDynamics,
|
|
prevDynamics,
|
|
|
context,
|
|
context,
|
|
|
- // the logical index of append child (kept for backward compatibility)
|
|
|
|
|
|
|
+ // the logical index of append child
|
|
|
dynamicCount + staticCount,
|
|
dynamicCount + staticCount,
|
|
|
true,
|
|
true,
|
|
|
)
|
|
)
|
|
@@ -112,14 +113,13 @@ function processDynamicChildren(context: TransformContext<ElementNode>) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function registerInsertion(
|
|
function registerInsertion(
|
|
|
- dynamics: IRDynamicInfo[],
|
|
|
|
|
|
|
+ dynamics: (IRDynamicInfo & { logicalIndex?: number })[],
|
|
|
context: TransformContext,
|
|
context: TransformContext,
|
|
|
anchor: number,
|
|
anchor: number,
|
|
|
append?: boolean,
|
|
append?: boolean,
|
|
|
) {
|
|
) {
|
|
|
for (const child of dynamics) {
|
|
for (const child of dynamics) {
|
|
|
- const logicalIndex = (child as IRDynamicInfo & { logicalIndex?: number })
|
|
|
|
|
- .logicalIndex
|
|
|
|
|
|
|
+ const logicalIndex = child.logicalIndex
|
|
|
if (child.template != null) {
|
|
if (child.template != null) {
|
|
|
// template node due to invalid nesting - generate actual insertion
|
|
// template node due to invalid nesting - generate actual insertion
|
|
|
context.registerOperation({
|
|
context.registerOperation({
|