Dynamic CSS import via await import() fails silently with Symfony Asset Mapper
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- javascript, symfony
- Domain
- documentation
Research direction
Start with the optional-extension documentation and examples, then compare their CSS-loading guidance with the Symfony Asset Mapper documentation linked in the issue. Update the relevant examples or notes to show that CSS uses a static top-level import, and confirm the guidance covers bundler-free setups without changing the conditional JavaScript loading pattern.
Written by the indexing model from the issue text.
Description
Summary
When integrating DataTables ColumnControl (or other extensions) with Symfony Asset Mapper, the recommended pattern of dynamically importing CSS inside an async try/catch block silently fails — the CSS is never loaded.
Pattern that fails
try {
await import('datatables.net-columncontrol-bs5');
await import('datatables.net-columncontrol-bs5/css/columnControl.bootstrap5.min.css');
dtPlugins.columnControl = true;
} catch (error) {
console.warn('ColumnControl unavailable', error);
}
Symfony Asset Mapper uses native ES modules and a static importmap. It only processes static top-level import statements at build time. Dynamic import() expressions inside async functions are not analysed for CSS, so the CSS file is never injected into the page.
The JS loads fine (the extension initialises), but without its stylesheet the controls render incorrectly — in our case, the ColumnControl search input was invisible because none of the dtcc-* CSS rules were applied.
Fix
Move the CSS import to a static top-level import, separate from the conditional JS load:
// Static — processed by Asset Mapper at build time
import 'datatables.net-columncontrol-bs5/css/columnControl.bootstrap5.min.css';
// Dynamic — still fine for JS (optional/conditional loading)
try {
await import('datatables.net-columncontrol-bs5');
dtPlugins.columnControl = true;
} catch (error) {
console.warn('ColumnControl unavailable', error);
}
Context
- Symfony Asset Mapper: https://symfony.com/doc/current/frontend/asset_mapper.html
- Uses a static
importmap.json/importmap.php— no bundler (webpack/vite) - Dynamic CSS imports work fine with Vite/webpack but not with Asset Mapper
- The extension JS loads correctly; only CSS is affected
Suggestion
The docs/examples for optional extensions could note that CSS imports must be static when using bundler-free setups like Symfony Asset Mapper, or provide a <link> tag fallback alongside the JS example.
- Dominant language
- JavaScript
- Stars
- 801
- Forks
- 440
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DataTables/DataTablesSrc
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
DataTables/DataTablesSrc#372 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
DataTables/DataTablesSrc#361 · 5 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
DataTables/DataTablesSrc#289 · 8 comments ·
All issues in DataTables/DataTablesSrc
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·