Skip to content

Commit

Permalink
fix(runtime-vapor): don't overridden attrs in static template
Browse files Browse the repository at this point in the history
closes #253
  • Loading branch information
sxzz committed Nov 13, 2024
1 parent 5f92ff8 commit 39f85ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-vapor/src/apiCreateComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function createComponent(
slots,
once,
)
setupComponent(instance, singleRoot)
setupComponent(instance)

// register sub-component with current component for lifecycle management
current.comps.add(instance)
Expand Down
7 changes: 2 additions & 5 deletions packages/runtime-vapor/src/apiRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export type Fragment = {
[fragmentKey]: true
}

export function setupComponent(
instance: ComponentInternalInstance,
singleRoot: boolean = false,
): void {
export function setupComponent(instance: ComponentInternalInstance): void {
if (__DEV__) {
startMeasure(instance, `init`)
}
Expand Down Expand Up @@ -97,7 +94,7 @@ export function setupComponent(
block = []
}
instance.block = block
if (singleRoot) fallThroughAttrs(instance)
fallThroughAttrs(instance)
return block
})
reset()
Expand Down
8 changes: 7 additions & 1 deletion packages/runtime-vapor/src/componentAttrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export function fallThroughAttrs(instance: ComponentInternalInstance): void {
if (inheritAttrs === false) return

if (block instanceof Element) {
renderEffect(() => setDynamicProps(block, instance.attrs))
// attrs in static template
const initial: Record<string, string> = {}
for (let i = 0; i < block.attributes.length; i++) {
const attr = block.attributes[i]
initial[attr.name] = attr.value
}
renderEffect(() => setDynamicProps(block, instance.attrs, initial))
}
}

0 comments on commit 39f85ec

Please sign in to comment.