Environment
|
|
| Operating system |
macOS 25.2.0 |
| CPU |
Apple M2 Pro (10 cores) |
| Node.js version |
v24.7.0 |
| nuxt/cli version |
3.31.2 |
| Package manager |
pnpm@10.28.1 |
| Nuxt version |
4.2.2 |
| Nitro version |
2.13.0 |
| Builder |
vite@7.2.7 |
| Config |
- |
| Modules |
- |
Is this bug related to Nuxt or Vue?
Nuxt
Package
v4.x
Version
v4.4.0
Reproduction
https://codesandbox.io/p/devbox/cocky-driscoll-6nnfkz?workspaceId=ws_VuFaVxsxE8szJ3rPbps3cW
Description
The current implementation of model modifiers always sets the output value to null/undefined if the input value is falsy:
function updateInput(value: string | null | undefined) {
if (props.modelModifiers?.trim) {
value = value?.trim() ?? null
}
if (props.modelModifiers?.number || props.type === 'number') {
value = looseToNumber(value)
}
if (props.modelModifiers?.nullable) {
value ||= null // 👈
}
if (props.modelModifiers?.optional) {
value ||= undefined // 👈
}
modelValue.value = value as T
emitFormInput()
}
I think these modifiers should only act on empty strings as turning 0 to null/undefined is very unexpected behavior.
I would be happy to implement these changes in a PR.
Additional context
No response
Logs
Environment
macOS 25.2.0Apple M2 Pro (10 cores)v24.7.03.31.2pnpm@10.28.14.2.22.13.0vite@7.2.7--Is this bug related to Nuxt or Vue?
Nuxt
Package
v4.x
Version
v4.4.0
Reproduction
https://codesandbox.io/p/devbox/cocky-driscoll-6nnfkz?workspaceId=ws_VuFaVxsxE8szJ3rPbps3cW
Description
The current implementation of model modifiers always sets the output value to
null/undefinedif the input value is falsy:I think these modifiers should only act on empty strings as turning
0tonull/undefinedis very unexpected behavior.I would be happy to implement these changes in a PR.
Additional context
No response
Logs