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

Incorrect dead code assumption on production mode #19435

Closed
7 tasks done
prashantpalikhe opened this issue Feb 16, 2025 · 3 comments
Closed
7 tasks done

Incorrect dead code assumption on production mode #19435

prashantpalikhe opened this issue Feb 16, 2025 · 3 comments
Labels
bug: upstream Bug in a dependency of Vite

Comments

@prashantpalikhe
Copy link

Describe the bug

During production build, a part of code incorrectly gets removed which is not removed during dev mode

Reproduction

https://stackblitz.com/edit/vitejs-vite-new1edjc

Steps to reproduce

In the repro link, during dev, the value of config1ValueForSomeComponent is config1DefaultValue and is shown in the HTML.

However, after npm run build && npm run preview, the value of config1ValueForSomeComponent is undefined as can be seen in the built preview HTML.

The code in question is:

const config = {
  someComponent: { someOtherConfig: false },
  default: { config1: 'config1DefaultValue' },
};

const config1ValueForSomeComponent =
  (config.someComponent || config.default).config1 || 'config1DefaultValue';

Here, config1ValueForSomeComponent is set to use the config1 property of either config.someComponent or config.default. Since the config.someComponent is an object, it should use the config1 property of that object. But since that object does not have config1 property, the value will be undefined and therefore the fallback of config1DefaultValue should be used.

However, in prod. build, the fallback code || 'config1DefaultValue' is stripped off and the value of config1ValueForSomeComponent is set to undefined.

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.1.0 => 6.1.0

Used Package Manager

npm

Logs

No response

Validations

@hi-ogawa
Copy link
Collaborator

I think this reproduces with pure rollup (repl link). Can you raise an issue on https://github.com/rollup/rollup/issues?

@hi-ogawa hi-ogawa added bug: upstream Bug in a dependency of Vite and removed pending triage labels Feb 16, 2025
@prashantpalikhe
Copy link
Author

Done.

rollup/rollup#5845

@hi-ogawa
Copy link
Collaborator

Closing since upstream is fixed. Confirmed on latest https://stackblitz.com/edit/vitejs-vite-c36ua73h?file=package.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: upstream Bug in a dependency of Vite
Projects
None yet
Development

No branches or pull requests

2 participants