Repository navigation
Restrict dynamic import contexts with webpackInclude - #1310
Merged
Merged
Conversation
… webpackInclude. Assisted-by: Claude Opus 5.5
…anguage. The language is cut to 2 letters, so e.g. "zh" was requested, for which fullcalendar has no locale. The failing import prevented the calendar from rendering. Assisted-by: Claude Opus 5.5
Only 2-letter locales can be requested. Every other file in the dynamic import context, including the *.global.js duplicates, was a chunk listed in the runtime of the entry points. Ref: ADR 0007 Assisted-by: Claude Opus 5.5
Only 2-letter locales can be requested. Every other file in the dynamic import context was a chunk listed in the runtime of the entry points. Ref: ADR 0007 Assisted-by: Claude Opus 5.5
…el themes. Restrict the languages to those of the highlight.js "common" build and the themes to the top-level ones, without the base16 themes. Every file in the dynamic import contexts was a chunk listed in the runtime of the entry points. Languages outside the common set fall back to highlightAuto. Ref: ADR 0007 Assisted-by: Claude Opus 5.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Dynamic imports with a template literal, such as
import(`moment/locale/${lang}.js`), make Webpack create a separate chunkfor every file that could match. Every one of those chunks gets an entry in
the chunk filename map of the Webpack runtime. That runtime is part of the
entry points
bundle.min.jsandremote.min.js. The lookup map of allmatching files also ends up in the eagerly loaded patterns chunk.
Four imports caused 766 of the 832 entries in the runtime chunk map:
highlight.js/lib/languages/${lang_file}highlight.js/styles/${theme_name}.css@fullcalendar/core/locales/${lang}.jsmoment/locale/${lang}.jsMoving such an import into a lazily loaded
--implementationmodule doesnot help. Webpack lists every async chunk reachable from the entry in the
runtime, however deeply the import is nested. A test build confirmed that
the entry points stayed the same size.
Changes
patterns cut the language to 2 letters, so locales like
zh-twor thefullcalendar
*.global.jsduplicates could never be requested. Nobehaviour change.
"common" build and the top-level themes, without
base16/.language. Before, e.g.
lang: zhmade the locale import fail and thecalendar never rendered. A test was added.
webpackIncludeis matched against the absolute file path, so the regularexpressions are anchored to the directory name (e.g.
/locales\/[a-z]{2}\.js$/), not to./.Results (production build)
bundle.min.jsremote.min.jsBehaviour changes in pat-syntax-highlight
dockerfile,nginx,django)fall back to
highlightAuto. That only knows the languages already loadedon the page, so these blocks are mostly not highlighted. Languages can be
added to the
webpackIncludelist insyntax-highlight.jswhen needed.base16/themes can no longer be passed as options from JavaScript. Thedocumented
themeoption only acceptsdarkandlight, so this has noeffect for markup-based usage.
Testing
npx jest src/pat/calendar src/pat/display-time src/pat/syntax-highlight:43 tests pass.
including
xml,python,javascriptand thestackoverflow-darkandstackoverflow-lightthemes.🤖 Generated with Claude Code