Skip to content

Fix code-split alias modules and dynamic CSS imports#10

Merged
dannote merged 2 commits intoelixir-volt:masterfrom
flowerornament:fix-code-split-dynamic-imports
May 1, 2026
Merged

Fix code-split alias modules and dynamic CSS imports#10
dannote merged 2 commits intoelixir-volt:masterfrom
flowerornament:fix-code-split-dynamic-imports

Conversation

@flowerornament
Copy link
Copy Markdown
Contributor

Summary

Closes #9.

This fixes two production code-splitting edge cases:

  • alias-resolved modules outside the entry root can be assigned collector labels such as _external/*; chunk output selection was matching by path suffix, so those modules could be omitted from the emitted chunk;
  • dynamic CSS imports such as import("./theme.css") should not survive as browser-runtime imports of CSS/data modules when Volt already owns stylesheet output.

The patch keeps Volt's existing chunk-graph approach, but makes three targeted changes:

  • select chunk files through the collector's original module path to label map;
  • protect dynamic import(...) before per-chunk OXC bundling, then restore it before Volt rewrites chunk URLs;
  • rewrite dynamic CSS import expressions to an already-resolved no-op promise. Static CSS imports continue to use the existing no-op JS-module path.

Repro

The public issue has the reduced cases and expected output: #9.

This PR adds tests for both cases:

  • code splitting includes alias modules outside the entry root
  • dynamic CSS imports become inert browser-loadable modules

Validation

  • mix format --check-formatted
  • mix test test/builder_test.exs --seed 0

AI disclosure

I used OpenAI Codex as a coding assistant to help reduce the repros and draft the candidate patch. I reviewed the diff and ran the validations above locally.

@flowerornament
Copy link
Copy Markdown
Contributor Author

This resolves my specific issue, but you may want to review for generality

@dannote
Copy link
Copy Markdown
Member

dannote commented May 1, 2026

Added follow-up commit cff4e66 with two extra safeguards for the code-splitting path:

  • minified output can turn import("./lazy") into a static template literal such as import(`./lazy.ts`); those are now recognized and rewritten to the emitted chunk file;
  • the temporary dynamic-import placeholder is now chosen per chunk input so it does not collide with user-defined identifiers.

Also added regression tests for both cases.

Checks:

  • mix format --check-formatted
  • mix test test/builder_test.exs --seed 0
  • mix test

@dannote
Copy link
Copy Markdown
Member

dannote commented May 1, 2026

Thank you for the detailed report and the PR — the reduced repros made this much easier to verify and extend.

@dannote dannote merged commit 57afd58 into elixir-volt:master May 1, 2026
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.

Code splitting can omit alias modules and mishandle dynamic CSS imports

2 participants