Skip to content

fix(frontend): pre-bundle the one dependency a story imports at runtime - #2398

Merged
dzarlax merged 1 commit into
constructorfabric:mainfrom
dzarlax:fix/storybook-exceljs-preoptimize
Aug 10, 2026
Merged

fix(frontend): pre-bundle the one dependency a story imports at runtime#2398
dzarlax merged 1 commit into
constructorfabric:mainfrom
dzarlax:fix/storybook-exceljs-preoptimize

Conversation

@dzarlax

@dzarlax dzarlax commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The xlsx export story fails on CI with

TypeError: Failed to fetch dynamically imported module: …/sb-vitest/deps/exceljs.js?v=…

and the failure is reported against whichever test happened to be running, not the one at fault — so it reads as an unrelated flake.

Why it happens

exceljs is reached through await import("exceljs") inside the export path, so vite's pre-bundling scan never reaches it from a story entry. It is discovered while the story runs: vite re-optimizes, reloads the page, and the very import that triggered the discovery dies with the page it was loading into.

This is exactly the case optimizeDeps.include already exists for in this config, and the comment above the list names this symptom in as many words. exceljs is also the only third-party package the source imports dynamically — every other await import(...) resolves an internal @/ alias, which vite treats as source and never pre-bundles. So this closes the class, not just one instance.

What I could not do

Reproduce it locally. A cold run with both node_modules/.vite and the storybook cache removed passes here with and without the change, so the race is one this machine does not lose. CI is the only place it has been observed.

That makes the fix reasoned rather than demonstrated, and it is worth saying plainly. What would disprove it: the same import failing again after this lands.

Why it is on its own

It blocks #2340 today and will catch anything else that touches those stories, so it should not wait behind a product change. Nothing else is in this branch.

Summary by CodeRabbit

  • Bug Fixes
    • Improved export test stability by preventing unnecessary reloads when using Excel-related functionality.

The xlsx export story fails on CI with "Failed to fetch dynamically imported
module … exceljs.js", and the file it lands on is whichever test was running at
the time rather than the one at fault.

`exceljs` is reached by `await import("exceljs")` inside the export path, so
vite's pre-bundling scan never sees it from the story entry. It is discovered
while the story runs, vite re-optimizes and reloads the page, and the import
that triggered the discovery dies with the page it was loading into.

This is the case the list already exists for, and the comment above it names
this exact symptom. It is also the only third-party package the source imports
dynamically — everything else behind `await import(...)` is an internal alias,
which vite resolves as source and never pre-bundles.

Not reproduced locally. A cold run with both `node_modules/.vite` and the
storybook cache removed still passes here, so the race is one this machine does
not lose; CI is the only place it has been seen. What would disprove the fix is
the same import failing again after this lands.

Signed-off-by: Alexey Panfilov <Alexey.Panfilov@constructor.tech>
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5bc1ec7f-615e-4832-9ba1-a4a47ac157c7

📥 Commits

Reviewing files that changed from the base of the PR and between 8079810 and 5ccf6a5.

📒 Files selected for processing (1)
  • src/frontend/vitest.config.ts

📝 Walkthrough

Walkthrough

The Storybook Vitest configuration now includes exceljs in Vite's dependency optimization list. A comment documents its runtime dynamic import behavior during export tests.

Changes

Storybook Vitest configuration

Layer / File(s) Summary
Pre-bundle exceljs for export tests
src/frontend/vitest.config.ts
The optimizeDeps.include list now contains exceljs. A comment documents the runtime dynamic import behavior.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Suggested reviewers: aleksdotbar

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes pre-bundling the runtime-imported dependency, which is the main change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dzarlax
dzarlax added this pull request to the merge queue Aug 10, 2026
Merged via the queue into constructorfabric:main with commit 42f43fe Aug 10, 2026
53 checks passed
@dzarlax
dzarlax deleted the fix/storybook-exceljs-preoptimize branch August 10, 2026 12:01
@dzarlax

dzarlax commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Correcting this after the fact: the change here did not fix the failure, and my note about what would disprove it was met almost immediately.

The body said "what would disprove the fix is the same import failing again after this lands." It did — on a merge-queue run whose base already contained this commit, with the identical exceljs.js message. Five pull requests landed anyway because the queue retried until an attempt happened to pass, which is exactly the behaviour that makes this read as a flake.

exceljs was never the cause. The line above the failure names it:

✨ new dependencies optimized: @base-ui/react/merge-props
✨ optimized dependencies changed. reloading

A dependency discovered mid-run makes vite reload the page, and the reload kills whichever import is in flight. That import is then reported as the failure — so the slowest thing to load takes the blame. I read the failing import as the cause instead of reading the line above it, and adding it to the list changed nothing.

#2399 lists all eighteen @base-ui/react/* entry points the source imports, nine of which were missing. exceljs stays: it is genuinely dynamic and belongs on the list, it just was not the problem.

Leaving this merged rather than reverting — the entry is correct on its own terms — but the claim in the body was wrong and should not be read as evidence that this class of failure was addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants