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): correctly handle number type props in prod #8989

Merged
merged 23 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7306078
fix(custom-element): Correctly handle number type props in prod
baiwusanyu-c Aug 16, 2023
981852f
fix(custom-element): added unit test
baiwusanyu-c Aug 16, 2023
df02ef9
chore: remove console
baiwusanyu-c Aug 17, 2023
bd3b0f5
chore: remove expect
baiwusanyu-c Aug 17, 2023
ad7dd23
chore: updated complier
baiwusanyu-c Aug 18, 2023
057886a
chore: format code
baiwusanyu-c Aug 21, 2023
b0d7417
chore: added isCE option to compiler sfc ctx
baiwusanyu-c Aug 21, 2023
8f1da9a
chore: updated unit test
baiwusanyu-c Aug 21, 2023
cc0ff63
Merge branch 'main' into bwsy/fix/CENumProps
baiwusanyu-c Aug 21, 2023
4a651d1
chore: added customElement options in SFCScriptCompileOptions
baiwusanyu-c Aug 22, 2023
f070820
Merge branch 'main' into bwsy/fix/CENumProps
baiwusanyu-c Aug 22, 2023
26fd1e3
Merge remote-tracking branch 'origin/bwsy/fix/CENumProps' into bwsy/f…
baiwusanyu-c Aug 22, 2023
dbfaf97
chore: updated code
baiwusanyu-c Aug 22, 2023
916388e
Merge branch 'main' into bwsy/fix/CENumProps
baiwusanyu-c Sep 5, 2023
64f9c5d
Merge branch 'main' into bwsy/fix/CENumProps
baiwusanyu-c Oct 20, 2023
6d0c7b4
Merge branch 'main' into bwsy/fix/CENumProps
baiwusanyu-c Oct 26, 2023
d2d98e6
Merge branch 'main' into bwsy/fix/CENumProps
baiwusanyu-c Oct 31, 2023
af82b74
Merge branch 'main' into bwsy/fix/CENumProps
baiwusanyu-c Nov 1, 2023
a7d48fb
Merge branch 'main' into bwsy/fix/CENumProps
baiwusanyu-c Nov 10, 2023
d73f608
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 10, 2023
eb89b9e
Merge remote-tracking branch 'origin/main' into bwsy/fix/CENumProps
baiwusanyu-c Nov 13, 2023
3564fce
Merge branch 'main' into bwsy/fix/CENumProps
baiwusanyu-c Nov 30, 2023
3640d9f
Merge branch 'main' into bwsy/fix/CENumProps
baiwusanyu-c Dec 5, 2023
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
20 changes: 20 additions & 0 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
renderSlot,
VueElement
} from '../src'
import { expect } from 'vitest'

describe('defineCustomElement', () => {
const container = document.createElement('div')
Expand Down Expand Up @@ -283,6 +284,25 @@ describe('defineCustomElement', () => {
expect(el.maxAge).toBe(50)
expect(el.shadowRoot.innerHTML).toBe('max age: 50/type: number')
})

// #8987
test('Correctly handle number type props in prod', () => {
const E = defineCustomElement({
props: {
foo: {
default: 5
}
},
render() {
// @ts-ignore
return `foo: ${typeof this.foo}`
}
})
customElements.define('my-element-number-property-prod', E)
container.innerHTML = `<my-element-number-property-prod foo="5.5"></my-element-number-property-prod>`
const e = container.childNodes[0] as VueElement
expect(e.shadowRoot!.innerHTML).toBe('foo: number')
})
})

describe('attrs', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/runtime-dom/src/apiCustomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ export class VueElement extends BaseClass {
if (props && !isArray(props)) {
for (const key in props) {
const opt = props[key]
if (opt === Number || (opt && opt.type === Number)) {
if (
opt === Number ||
(opt && (opt.type === Number || typeof opt.default === 'number'))
) {
if (key in this._props) {
this._props[key] = toNumber(this._props[key])
}
Expand Down Expand Up @@ -360,6 +363,7 @@ export class VueElement extends BaseClass {
}

private _createVNode(): VNode<any, any> {
console.log('####', this._props)
baiwusanyu-c marked this conversation as resolved.
Show resolved Hide resolved
const vnode = createVNode(this._def, extend({}, this._props))
if (!this._instance) {
vnode.ce = instance => {
Expand Down