Skip to content

Commit 25d1c09

Browse files
authored
feat: Lazy loading and code splitting (#1802)
This adds lazy loading for `chart` and `iris-grid` and enables it for `MarkdownComponent` as well. Replaced the exports for `Chart` and `IrisGrid` with lazy loading wrappers. This should mean anywhere else we use the components in the app should be automatically lazy loaded.
1 parent 69e8cdd commit 25d1c09

24 files changed

Lines changed: 164 additions & 19 deletions

packages/chart/src/LazyChart.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { LoadingOverlay } from '@deephaven/components';
2+
import { lazy, Suspense } from 'react';
3+
4+
const Chart = lazy(() => import('./Chart.js'));
5+
6+
function LazyChart(props: React.ComponentProps<typeof Chart>): JSX.Element {
7+
return (
8+
<Suspense fallback={<LoadingOverlay />}>
9+
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
10+
<Chart {...props} />
11+
</Suspense>
12+
);
13+
}
14+
15+
export default LazyChart;

packages/chart/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
export { default as Chart } from './Chart';
1+
export { default as Chart } from './LazyChart';
22
export { default as ChartModelFactory } from './ChartModelFactory';
33
export { default as ChartModel } from './ChartModel';
44
export { default as ChartUtils } from './ChartUtils';
55
export * from './ChartUtils';
66
export * from './DownsamplingError';
77
export { default as FigureChartModel } from './FigureChartModel';
88
export { default as MockChartModel } from './MockChartModel';
9-
export { default as Plot } from './plotly/Plot';
9+
export { default as Plot } from './plotly/LazyPlot';
1010
export * from './ChartTheme';
1111
export * from './ChartThemeProvider';
1212
export { default as isFigureChartModel } from './isFigureChartModel';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { LoadingOverlay } from '@deephaven/components';
2+
import { lazy, Suspense } from 'react';
3+
4+
const PlotBase = lazy(() => import('./Plot.js'));
5+
6+
function Plot(props: React.ComponentProps<typeof PlotBase>): JSX.Element {
7+
return (
8+
<Suspense fallback={<LoadingOverlay />}>
9+
{/* eslint-disable react/jsx-props-no-spreading */}
10+
<PlotBase {...props} />
11+
</Suspense>
12+
);
13+
}
14+
15+
export default Plot;

packages/code-studio/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ export default defineConfig(({ mode }) => {
122122
if (id.includes('plotly.js')) {
123123
return 'plotly';
124124
}
125+
if (id.includes('mathjax')) {
126+
return 'mathjax';
127+
}
125128
return 'vendor';
126129
}
127130
},

packages/components/src/theme/theme-spectrum/theme-spectrum-alias.module.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/* stylelint-disable custom-property-empty-line-before */
22
/* stylelint-disable alpha-value-notation */
3-
.dh-spectrum-alias {
3+
4+
/**
5+
* Intentionally using the classname twice so we have higher specificity than spectrum's definitions
6+
* This is to ensure that our overrides are applied regardless of CSS chunk loading order
7+
*/
8+
.dh-spectrum-alias.dh-spectrum-alias {
49
/*********** Override variables in spectrum-global.css **********************/
510
--spectrum-alias-background-color-default: var(--dh-color-bg);
611
--spectrum-alias-background-color-disabled: var(--dh-color-disabled-bg);

packages/components/src/theme/theme-spectrum/theme-spectrum-palette.module.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
.dh-spectrum-palette {
1+
/**
2+
* Intentionally using the classname twice so we have higher specificity than spectrum's definitions
3+
* This is to ensure that our overrides are applied regardless of CSS chunk loading order
4+
*/
5+
.dh-spectrum-palette.dh-spectrum-palette {
26
/* Gray */
37
--spectrum-gray-50: var(--dh-color-gray-50);
48
--spectrum-gray-75: var(--dh-color-gray-75);

packages/console/src/notebook/ScriptEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LoadingOverlay, ShortcutRegistry } from '@deephaven/components';
66
import Log from '@deephaven/log';
77
import type { IdeSession } from '@deephaven/jsapi-types';
88
import { assertNotNull } from '@deephaven/utils';
9-
import { editor, IDisposable } from 'monaco-editor';
9+
import type { editor, IDisposable } from 'monaco-editor';
1010
import Editor from './Editor';
1111
import { MonacoProviders, MonacoUtils } from '../monaco';
1212
import './ScriptEditor.scss';

packages/dashboard-core-plugins/src/panels/IrisGridPanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import {
2020
AdvancedSettings,
2121
IrisGrid,
22+
type IrisGridType,
2223
IrisGridModel,
2324
IrisGridUtils,
2425
isIrisGridTableModelTemplate,
@@ -362,7 +363,7 @@ export class IrisGridPanel extends PureComponent<
362363
}
363364
}
364365

365-
irisGrid: RefObject<IrisGrid>;
366+
irisGrid: RefObject<IrisGridType>;
366367

367368
pluginRef: RefObject<TablePluginElement>;
368369

packages/iris-grid/src/IrisGrid.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dh from '@deephaven/jsapi-shim';
44
import { DateUtils, Settings } from '@deephaven/jsapi-utils';
55
import { TestUtils } from '@deephaven/utils';
66
import { TypeValue } from '@deephaven/filters';
7-
import { IrisGrid } from './IrisGrid';
7+
import IrisGrid from './IrisGrid';
88
import IrisGridTestUtils from './IrisGridTestUtils';
99

1010
class MockPath2D {

packages/iris-grid/src/IrisGrid.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ function isEmptyConfig({
249249
sorts.length === 0
250250
);
251251
}
252+
252253
export type FilterData = {
253254
operator: FilterTypeValue;
254255
text: string;
@@ -451,7 +452,7 @@ export interface IrisGridState {
451452
columnHeaderGroups: readonly ColumnHeaderGroup[];
452453
}
453454

454-
export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
455+
class IrisGrid extends Component<IrisGridProps, IrisGridState> {
455456
static contextType = IrisGridThemeContext;
456457

457458
static minDebounce = 150;

0 commit comments

Comments
 (0)