Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(custom-element): reflect prop default value #10537

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ export interface ComponentInternalInstance {
*/
ceReload?: (newStyles?: string[]) => void

/**
* custom element set prop
* @internal
*/
ceSetProp?: (prop: string, value: any) => void

// the rest are only for stateful components ---------------------------------

// main proxy that serves as the public instance (`this`)
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ function resolvePropValue(
} else {
value = defaultValue
}

if (instance.isCE) {
instance.ceSetProp!(key, value)
}
}
// boolean casting
if (opt[BooleanFlags.shouldCast]) {
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('defineCustomElement', () => {
expect(e).toBeInstanceOf(E)
expect(e._instance).toBeTruthy()
expect(e.shadowRoot!.innerHTML).toBe(`<div>hello</div>`)
expect(e.getAttribute('msg')).toBe(`hello`)
})

test('should work w/ manual instantiation', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime-dom/src/apiCustomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ export class VueElement extends BaseClass {
break
}
}

instance.ceSetProp = (key: string, value: any) => {
this._setProp(key, value, true, false)
}
}
}
return vnode
Expand Down