perf(admin-ui): split bundles with lazy routes and vendor chunks#2453
Open
dirkwa wants to merge 2 commits intoSignalK:masterfrom
Open
perf(admin-ui): split bundles with lazy routes and vendor chunks#2453dirkwa wants to merge 2 commits intoSignalK:masterfrom
dirkwa wants to merge 2 commits intoSignalK:masterfrom
Conversation
Plugins built with React 16 (webpack Module Federation) crash in the React 19 admin UI due to singleton resolution picking R19 over R16, causing hook errors (SignalK#321) and element type mismatches (SignalK#525). Fix by temporarily hiding R19 share scope entries during container initialization so webpack resolves to R16, then rendering legacy components in isolated R16 subtrees via ReactDOM 16's render(). For plugins that share react but not react-dom (bt-sensors, shelly2), fall back to a bundled ReactDOM 16 UMD loaded with the plugin's own R16 instance to keep hooks working. Defer R16 rendering via setTimeout(0) to avoid interfering with R19's commit phase on soft navigation.
The admin UI shipped a single 2.1MB bootstrap chunk containing all view code and all npm dependencies. This adds route-level code splitting via React.lazy() and extracts heavy vendor libraries (mathjs, @rjsf, react-select) into separate chunks via manualChunks. Initial load drops from 2.1MB to ~500KB. The heaviest vendor chunks (mathjs 636KB, @rjsf 409KB) are only fetched when navigating to DataBrowser or Plugin Configuration routes. Also removes the full lodash CJS import (138KB) from actions.ts, replacing the single isUndefined() call with a plain === check.
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.
Motivation
math.jsnow in the UI and ballooned the bundle to > 2MB.Summary
The admin UI shipped everything in a single 2.1MB JavaScript bundle. This splits it using route-level code splitting and vendor chunk extraction, reducing the initial page load to ~500KB.
React.lazy()with aSuspenseboundary — Dashboard, Login, Register, Webapps, Embedded, and EmbeddedDocs stay eagerly loadedvendor-mathjschunk viamanualChunks— only fetched when navigating to the Data Browseractions.ts, replacing a singleisUndefined()call with=== undefinedVite's own code splitting naturally groups @rjsf/ajv into the Configuration route chunk (~418KB, loaded only on plugin config) and react-select into a shared chunk (~86KB, loaded by Data Browser/Server Log/Connections).
Note:
manualChunksis limited to mathjs (pure math, no React imports) because@module-federation/viterewrites React imports into async share-scope resolution with top-level await — forcing React-dependent packages into separate vendor chunks breaks the MF initialization order.Bundle comparison
Note