docs: clarify lazy plugin side effects#1841
Conversation
✅ Deploy Preview for viteplus-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8104d7e2cc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| ```ts [vite.config.ts] | ||
| import { defineConfig } from 'vite-plus'; | ||
| import { defineConfig } from "vite-plus"; |
There was a problem hiding this comment.
Can the format replacement of single quotes be reverted? These should not need changes.
| When `vite.config.ts` imports heavy plugins at the top level, every `import` is evaluated eagerly, even for commands like `vp lint` or `vp fmt` that don't need those plugins. This can make config loading noticeably slow. | ||
|
|
||
| Eager plugins can also run unexpected side effects in long-lived tooling processes, such as editor integrations, format or lint language servers, and background workers. If a plugin touches the file system, starts a watcher, reads environment-specific files, or talks to a service during setup, prefer loading it through `lazyPlugins` so those side effects only happen for commands that actually execute the Vite pipeline. | ||
|
|
||
| Use `lazyPlugins` to wrap plugin loading. Plugins are only loaded for commands that need them (`dev`, `build`, `test`, `preview`), and skipped for everything else: |
There was a problem hiding this comment.
The added guidance is useful, but the new paragraph feels a bit dense. I’d suggest merging the background-process and side-effect examples into a shorter version:
| When `vite.config.ts` imports heavy plugins at the top level, every `import` is evaluated eagerly, even for commands like `vp lint` or `vp fmt` that don't need those plugins. This can make config loading noticeably slow. | |
| Eager plugins can also run unexpected side effects in long-lived tooling processes, such as editor integrations, format or lint language servers, and background workers. If a plugin touches the file system, starts a watcher, reads environment-specific files, or talks to a service during setup, prefer loading it through `lazyPlugins` so those side effects only happen for commands that actually execute the Vite pipeline. | |
| Use `lazyPlugins` to wrap plugin loading. Plugins are only loaded for commands that need them (`dev`, `build`, `test`, `preview`), and skipped for everything else: | |
| When `vite.config.ts` imports plugins at the top level, they are evaluated for every command, including `vp lint`, `vp fmt`, editor integrations, and long-lived background processes. This can make config loading slow and may trigger plugin setup side effects, such as reading files, starting watchers, or connecting to services. | |
| Use `lazyPlugins` to load plugins only when the Vite pipeline actually runs (`dev`, `build`, `test`, `preview`): |
This keeps the same intent while making the guidance easier to scan.
Summary
lazyPluginsfor plugins with setup-time side effectsAddresses #1580 by covering the LSP/background-process case in the troubleshooting guidance.
Verification
pnpm exec oxfmt --check docs/guide/troubleshooting.mdnode -e "const fs=require('fs'); const text=fs.readFileSync('docs/guide/troubleshooting.md','utf8'); for (const s of ['long-lived tooling processes','editor integrations','format or lint language servers','lazyPlugins']) if (!text.includes(s)) throw new Error('missing '+s); console.log('lazy plugin docs ok')"