-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
mergeConfig
doesn't merge null
or undefined
values
#18943
Comments
I guess the reason why // this won't work if `undefined` is not excluded
mergeConfig(originalConfig, {
envDir: client ? './something' : undefined
})
// it has to be like
mergeConfig(originalConfig, {
...(client ? { envDir: './something' } : {})
}) For I think it's more intuitive if we change this line to vite/packages/vite/src/node/utils.ts Line 1171 in 3400a5e
But this condition has been there from the beginning so may cause some breakage. I wonder if we should receive |
I think if we want to adjust for this situation, maybe we can add a new parameter vite/packages/vite/src/node/utils.ts Lines 1225 to 1231 in 3400a5e
|
That would make the behavior inconsistent between frameworks and I think that is confusing. The users of |
What I want is to give the parameter a default value of true, so that it will be consistent with the original default behavior when no value is passed. |
Describe the bug
When using
mergeConfig
, it is impossible to mergenull
orundefined
values into the base config.I've encountered this while using Remix ≥ 2.14.0, where
vite.mergeConfig
is used to merge a value forserver.watch
into the base config. This doesn't work fornull
orundefined
values, which are the only two values Remix tries to merge.(See here for the
mergeConfig
call and here for the data that's passed into it).This results in the
server.watch
value never actually being set to anything in the final config, which in turn leads to a whole bunch of files being watched by vite that don't actually need watching during a build.I'm not sure what the rationale was for excluding
null
andundefined
values when merging values, but I do see some use-cases for allowing them to be merged, like how remix tries (and fails) to do it.Without additional context, I would expect any values in the
overrides
record to overwrite thedefault
value, no matter what its value is. If I don't want to override a value, I shouldn't include its key in theoverrides
in the first place, so evenundefined
shouldn't receive special treatment as far as I'm concerned.I've not submitted a PR because I'm not sure what other unforeseen side-effects the removal of that check would have.
I'd also be fine with keeping the check as-is, but then at the very least this quirk should be included in the documentation.
Reproduction
https://stackblitz.com/edit/vitejs-vite-66qrvrft?file=index.js
Steps to reproduce
No response
System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 18.20.3 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 10.2.3 - /usr/local/bin/npm pnpm: 8.15.6 - /usr/local/bin/pnpm npmPackages: vite: ^6.0.3 => 6.0.3
Used Package Manager
npm
Logs
Validations
The text was updated successfully, but these errors were encountered: