Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ jobs:
- name: Main ESlint check
run: pnpm lint

vite-optimize-deps:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
name: Vite optimizeDeps audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Node.js environment
uses: ./.github/actions/node_env_setup
with:
node-version: ${{ env.node-version }}

- name: Check optimizeDeps declarations are up to date
run: pnpm check:vite-optimize-deps

stylelint:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
name: Stylelint ${{ matrix.name }}
Expand Down
1 change: 1 addition & 0 deletions apps/aurora/news/+vite-optimize-deps-ssr-exclude.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Excluded `i18next-fs-backend` and `remix-i18next/server` from the client `optimizeDeps` bundle — they were still being picked up by Vite's client-side dependency scanner despite only being declared in `ssr.optimizeDeps.include`. @sneridagh
2 changes: 1 addition & 1 deletion apps/aurora/news/+vite-optimize-deps.internal
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Added `optimizeDeps.include` entries for non-addon workspace packages and app-level deps, eliminating lazy dependency discovery reloads on dev server startup. @arybakov05
Added `optimizeDeps.include` entries for non-addon workspace packages and app-level deps to reduce lazy dependency discovery reloads on dev server startup. @arybakov05
10 changes: 9 additions & 1 deletion apps/aurora/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export default defineConfig(({ command, mode, isSsrBuild }) => {
: []),
] as PluginOption[],
optimizeDeps: {
// Server-only deps that Vite would otherwise still pick up for the
// client bundle — keep in sync with ssr.optimizeDeps.include below
exclude: [
'i18next-fs-backend',
'i18next-fs-backend/cjs',
'remix-i18next/server',
],
include: [
// App-level deps (in apps/aurora/package.json)
'i18next',
Expand All @@ -66,6 +73,7 @@ export default defineConfig(({ command, mode, isSsrBuild }) => {
'@plone/components > react-aria',
'@plone/components > react-aria-components',
'@plone/components > react-aria-components/DropZone',
'@plone/components > react-aria-components/Form',
'@plone/components > react-aria-components/Group',
'@plone/components > react-aria-components/Modal',
'@plone/components > react-aria-components/Table',
Expand All @@ -81,7 +89,7 @@ export default defineConfig(({ command, mode, isSsrBuild }) => {
},
ssr: {
optimizeDeps: {
include: ['i18next-fs-backend/cjs', 'remix-i18next/server'],
include: ['i18next-fs-backend/cjs', 'isbot', 'remix-i18next/server'],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried running from this feature branch locally, and it seems that Vite is still picking up the i18next-fs-backend/cjs and remix-i18next/server dependencies for the client optimizer.

Image

The fix is to explicitly exclude them in the client optimizeDeps as such:

optimizeDeps: {
      exclude: [
        'i18next-fs-backend',
        'i18next-fs-backend/cjs',
        'remix-i18next/server',
      ],
      include: [
       ...
      ]
Image

},
},
resolve: {
Expand Down
33 changes: 32 additions & 1 deletion docs/development/vite-optimize-deps.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ myst:

# Vite dependency pre-bundling

This guide shows you how to declare third-party dependencies for pre-bundling so Vite resolves them at startup rather than lazily during dev.
This guide shows you how to declare third-party dependencies for pre-bundling so Vite resolves more of them at startup instead of discovering them lazily during dev.

Aurora runs in a pnpm monorepo.
Vite treats workspace packages as source files and does not scan them upfront for their third-party dependencies.
Expand Down Expand Up @@ -66,6 +66,37 @@ If a dependency exports subpaths you use (for example `some-lib/react` or `some-
Vite does not discover subpath exports automatically from the main entry.

If a dependency is only used in server-side code (for example `*.server.*` files), add it to `ssr.optimizeDeps.include` instead of `optimizeDeps.include` so it isn't pre-bundled for the browser.
Declaring it in `ssr.optimizeDeps.include` alone is not always enough — Vite's client-side dependency scanner can still pick it up through re-exports.
If that happens, also add it to the top-level `optimizeDeps.exclude` in `apps/aurora/vite.config.ts` so it's explicitly kept out of the client bundle.

To keep the lists from drifting, run:

```sh
pnpm check:vite-optimize-deps
```

The script inspects runtime imports in the workspace packages that require explicit declarations and reports missing or stale `pkg > dep` entries.

Run it when:

- you add or remove a runtime import in `@plone/components`, `@plone/helpers`,
`@plone/cmsui`, `@plone/layout`, or `@plone/plate`
- you switch an import to a different package subpath such as
`some-lib/react`
- you move an import between browser-only and server-only code and may need to
switch between `optimizeDeps.include` and `ssr.optimizeDeps.include`
- you touch one of the existing optimize-deps config files and want to verify
the list before opening a PR

Recommended workflow:

1. Make the code change that introduces or removes runtime imports.
2. Run `pnpm check:vite-optimize-deps`.
3. Copy the reported missing entries into the relevant `vite.extend.js` file or
`apps/aurora/vite.config.ts`.
4. Remove reported stale entries unless you have a concrete reason to keep
them.
5. Re-run the check until it passes.

### Existing core add-on files

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test": "pnpm --filter @plone/aurora run test",
"test:all": "pnpm test:ci",
"test:ci": "pnpm --filter @plone/* --filter \"!@plone/scripts\" --filter \"!@plone/theming\" run test --run",
"check:vite-optimize-deps": "node packages/scripts/check-vite-optimize-deps.js",
"prettier": "prettier --check '{apps,packages}/**/*.{js,jsx,ts,tsx}'",
"prettier:fix": "prettier --write '{apps,packages}/**/*.{js,jsx,ts,tsx}'",
"stylelint": "stylelint '{apps,packages}/**/*.{css,scss,less}'",
Expand Down
2 changes: 1 addition & 1 deletion packages/cmsui/news/+vite-optimize-deps.internal
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Added `vite.extend.js` to pre-bundle CMS UI dependencies, reducing dev server startup reloads. @arybakov05
Added `vite.extend.js` and a dependency audit path to pre-bundle CMS UI runtime dependencies, reducing dev server startup reloads. @arybakov05
18 changes: 18 additions & 0 deletions packages/cmsui/vite.extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@ export default function (config) {
...config.optimizeDeps,
include: [
...(config.optimizeDeps?.include ?? []),
'@plone/cmsui > @platejs/floating',
'@plone/cmsui > @platejs/link/react',
'@plone/cmsui > @tanstack/react-form',
'@plone/cmsui > class-variance-authority',
'@plone/cmsui > clsx',
'@plone/cmsui > jotai',
'@plone/cmsui > jotai-optics',
'@plone/cmsui > jotai/utils',
'@plone/cmsui > jwt-decode',
'@plone/cmsui > lucide-react',
'@plone/cmsui > platejs',
'@plone/cmsui > platejs/react',
'@plone/cmsui > react-aria',
'@plone/cmsui > react-aria-components',
'@plone/cmsui > react-i18next',
'@plone/cmsui > react-router',
'@plone/cmsui > rrule',
'@plone/cmsui > tailwind-merge',
'@plone/cmsui > tailwind-variants',
'@plone/cmsui > usehooks-ts',
],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/layout/news/+vite-optimize-deps.internal
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Added `vite.extend.js` to pre-bundle layout dependencies, reducing dev server startup reloads. @arybakov05
Added `vite.extend.js` and a dependency audit path to pre-bundle layout runtime dependencies, reducing dev server startup reloads. @arybakov05
5 changes: 5 additions & 0 deletions packages/layout/vite.extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ export default function (config) {
...config.optimizeDeps,
include: [
...(config.optimizeDeps?.include ?? []),
'@plone/layout > clsx',
'@plone/layout > lodash.sortby',
'@plone/layout > pretty-bytes',
'@plone/layout > react-aria',
'@plone/layout > react-aria-components',
'@plone/layout > react-i18next',
'@plone/layout > react-router',
'@plone/layout > rrule',
],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plate/news/+vite-optimize-deps.internal
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Added `vite.extend.js` to pre-bundle platejs and Radix UI dependencies, reducing dev server startup reloads. @arybakov05
Added `vite.extend.js` and a dependency audit path to pre-bundle Plate runtime dependencies, reducing dev server startup reloads. @arybakov05
43 changes: 43 additions & 0 deletions packages/plate/vite.extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,86 @@ export default function (config) {
...config.optimizeDeps,
include: [
...(config.optimizeDeps?.include ?? []),
'@plone/plate > @ai-sdk/react',
'@plone/plate > @ariakit/react',
'@plone/plate > @platejs/ai',
'@plone/plate > @platejs/ai/react',
'@plone/plate > @platejs/autoformat',
'@plone/plate > @platejs/basic-nodes',
'@plone/plate > @platejs/basic-nodes/react',
'@plone/plate > @platejs/basic-styles',
'@plone/plate > @platejs/basic-styles/react',
'@plone/plate > @platejs/callout',
'@plone/plate > @platejs/callout/react',
'@plone/plate > @platejs/caption',
'@plone/plate > @platejs/caption/react',
'@plone/plate > @platejs/code-block',
'@plone/plate > @platejs/code-block/react',
'@plone/plate > @platejs/combobox',
'@plone/plate > @platejs/combobox/react',
'@plone/plate > @platejs/comment',
'@plone/plate > @platejs/comment/react',
'@plone/plate > @platejs/dnd',
'@plone/plate > @platejs/docx',
'@plone/plate > @platejs/emoji/react',
'@plone/plate > @platejs/floating',
'@plone/plate > @platejs/indent',
'@plone/plate > @platejs/indent/react',
'@plone/plate > @platejs/juice',
'@plone/plate > @platejs/layout',
'@plone/plate > @platejs/layout/react',
'@plone/plate > @platejs/link',
'@plone/plate > @platejs/link/react',
'@plone/plate > @platejs/list',
'@plone/plate > @platejs/list/react',
'@plone/plate > @platejs/markdown',
'@plone/plate > @platejs/media',
'@plone/plate > @platejs/media/react',
'@plone/plate > @platejs/mention',
'@plone/plate > @platejs/mention/react',
'@plone/plate > @platejs/playwright',
'@plone/plate > @platejs/resizable',
'@plone/plate > @platejs/selection/react',
'@plone/plate > @platejs/slash-command/react',
'@plone/plate > @platejs/suggestion',
'@plone/plate > @platejs/table',
'@plone/plate > @platejs/table/react',
'@plone/plate > @platejs/toc',
'@plone/plate > @platejs/toc/react',
'@plone/plate > @platejs/toggle',
'@plone/plate > @platejs/toggle/react',
'@plone/plate > @radix-ui/react-alert-dialog',
'@plone/plate > @radix-ui/react-avatar',
'@plone/plate > @radix-ui/react-checkbox',
'@plone/plate > @radix-ui/react-context-menu',
'@plone/plate > @radix-ui/react-dialog',
'@plone/plate > @radix-ui/react-dropdown-menu',
'@plone/plate > @radix-ui/react-popover',
'@plone/plate > @radix-ui/react-separator',
'@plone/plate > @radix-ui/react-slot',
'@plone/plate > @radix-ui/react-toolbar',
'@plone/plate > @radix-ui/react-tooltip',
'@plone/plate > @udecode/cn',
'@plone/plate > ai',
'@plone/plate > class-variance-authority',
'@plone/plate > clsx',
'@plone/plate > cmdk',
'@plone/plate > html2canvas-pro',
'@plone/plate > jotai',
'@plone/plate > lodash.debounce',
'@plone/plate > lowlight',
'@plone/plate > lucide-react',
'@plone/plate > pdf-lib',
'@plone/plate > platejs',
'@plone/plate > platejs/react',
'@plone/plate > react-dnd',
'@plone/plate > react-dnd-html5-backend',
'@plone/plate > react-lite-youtube-embed',
'@plone/plate > remark-gfm',
'@plone/plate > sonner',
'@plone/plate > tailwind-merge',
'@plone/plate > use-file-picker',
'@plone/plate > zod',
],
},
};
Expand Down
28 changes: 28 additions & 0 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,31 @@ It scans and detects i18n messages from the code and adds them to the i18n machi
See https://6.docs.plone.org/volto/development/i18n.html for more information.

This script is installed in the `node_modules/.bin` directory and can be called via `yarn i18n` or directly in the `scripts` `package.json` part.

## Aurora optimize-deps audit

Aurora includes a repository-level audit script at
`packages/scripts/check-vite-optimize-deps.js`.

Run it from the repo root with:

```sh
pnpm check:vite-optimize-deps
```

Use it when you change runtime imports in Aurora workspace packages that feed
the app through Vite:

- `@plone/components`
- `@plone/helpers`
- `@plone/cmsui`
- `@plone/layout`
- `@plone/plate`

The script scans those packages for runtime imports of direct third-party
dependencies and compares them with the explicit entries declared in
`apps/aurora/vite.config.ts` and `packages/*/vite.extend.js`.

If it reports missing entries, add them to the relevant optimize-deps config.
If it reports extra entries, remove them unless they are intentionally kept for
some unresolved import path.
Loading
Loading