fix: syncMode - default: use append strategy when using dev serve…#887
Conversation
|
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the syncMode: "default" behavior to properly use append strategy during development and overwrite strategy during build. Previously, the default mode was incorrectly using overwrite strategy when using the dev server.
- Introduces environment-based logic to determine the appropriate sync mode when
syncModeis set to"default" - Removes duplicate sync mode assignment that was overriding the intended behavior in dev server setup
- Adds clarifying comment explaining the default behavior logic
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| this._removeUnused = this.options.syncMode === 'overwrite' | ||
|
|
||
| // syncMode - `default`: use `append` strategy when using dev server, `overwrite` strategy when using build. | ||
| const syncMode = this.options.syncMode === 'default' ? (process.env.NODE_ENV === 'development' ? 'append' : 'overwrite') : this.options.syncMode |
There was a problem hiding this comment.
[nitpick] The ternary operator is nested and difficult to read. Consider extracting this logic into a separate method like resolveSyncMode() for better maintainability.
There was a problem hiding this comment.
Okay, I have fixed this issue and moved the logic to the options.ts file.
|
@xiaweiss IMO we should never relay on environment variables at this level. Development server being present does not mean running in Just have a look on previous implementation, it was using Therefore my opinion is that this changed may even break more use cases. If there's a bug we should have first a look at a reproduction that show something breaking when upgrading the version. I don't have more time for now to dive more in this, I'll let @antfu hopefully have a decision about what to do here. |
Thank you very much for your feedback. I will further research and explore how to determine the status of the dev-server. |
…r, `overwrite` strategy when using build.
|
update: process.env.NODE_ENV has been deprecated, and replaced with the setupWatcher hook. |
commit: |
fix: syncMode -
default: useappendstrategy when using dev server,overwritestrategy when using build.Description
Setting is:
syncMode: "default"The
overwritewas executed when using dev server.Updated: PR handles the
defaultoption within thesetupWatcherhook, and dev-server usesappendby default.The PR has added an environment variable check to handle the default behavior of "default".Relevant Pull Request
feat: introduce syncMode to control the behavior of generating files