fix: decouple core from lowlight to reduce bundle size#65
Open
voglster wants to merge 2 commits intoMrWangJustToDo:mainfrom
Open
fix: decouple core from lowlight to reduce bundle size#65voglster wants to merge 2 commits intoMrWangJustToDo:mainfrom
voglster wants to merge 2 commits intoMrWangJustToDo:mainfrom
Conversation
Syntax highlighting is lost when DiffView is unmounted and remounted with the same file content. The global File cache causes initRaw() → #syncSyntax() to copy highlighter metadata from cached File objects into a fresh DiffFile, making the syntax effect's guard condition evaluate to false and skip initSyntax() entirely. initSyntax() is already idempotent — when syntax is initialized with a matching highlighter, it efficiently re-syncs syntax line references without recomputing. Remove the guard condition and always call initSyntax() when highlighting is enabled. Fixes MrWangJustToDo#63
Remove the hard dependency on @git-diff-view/lowlight from core, which was causing all 130+ highlight.js language grammars (~870KB minified) to be bundled even when users provide their own highlighter. Changes: - core/file.ts: Replace direct highlighter import with injectable default via setDefaultHighlighter() - core/index.ts: Replace `export * from "@git-diff-view/lowlight"` with type-only re-exports - lowlight/index.ts: Auto-register as the default highlighter when imported via setDefaultHighlighter() - core/package.json: Move @git-diff-view/lowlight from dependencies to optional peerDependencies - Framework packages: Remove unused buildInHighlighter imports Users who provide a custom registerHighlighter can now avoid bundling lowlight entirely. Users who rely on the built-in lowlight highlighter just need to ensure @git-diff-view/lowlight is installed (which it is by default via the framework packages). BREAKING CHANGE: `highlighter` and `processAST` are no longer re-exported from @git-diff-view/core. Import them from @git-diff-view/lowlight instead. Fixes MrWangJustToDo#58
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.
Summary
@git-diff-view/coreon@git-diff-view/lowlight, eliminating ~870KB of unused highlight.js language grammars from the bundle when users provide their own highlightersetDefaultHighlighter()API to core for injectable highlighter registration@git-diff-view/lowlightauto-registers itself as the default when importedChanges
core/src/file.tsimport { highlighter }with injectable_defaultHighlighterviasetDefaultHighlighter()core/src/index.tsexport * from "@git-diff-view/lowlight"with type-only re-exportscore/package.json@git-diff-view/lowlightfromdependenciesto optionalpeerDependencieslowlight/src/index.tssetDefaultHighlighter(highlighter)on importlowlight/package.json@git-diff-view/coreas peer dependencybuildInHighlighterimportsBreaking Change
highlighterandprocessASTare no longer re-exported from@git-diff-view/core. Users should import them from@git-diff-view/lowlightdirectly.How it works
@git-diff-view/coreno longer imports any value from@git-diff-view/lowlight@git-diff-view/lowlightis imported (e.g., by framework packages or user code), it callssetDefaultHighlighter()to register itself with coreregisterHighlighterprop can skip installing@git-diff-view/lowlightentirely, and the highlight.js bundle is never includedFixes #58