-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
69e8cdd
commit 25d1c09
Showing
24 changed files
with
164 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { LoadingOverlay } from '@deephaven/components'; | ||
import { lazy, Suspense } from 'react'; | ||
|
||
const Chart = lazy(() => import('./Chart.js')); | ||
|
||
function LazyChart(props: React.ComponentProps<typeof Chart>): JSX.Element { | ||
return ( | ||
<Suspense fallback={<LoadingOverlay />}> | ||
{/* eslint-disable-next-line react/jsx-props-no-spreading */} | ||
<Chart {...props} /> | ||
</Suspense> | ||
); | ||
} | ||
|
||
export default LazyChart; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { LoadingOverlay } from '@deephaven/components'; | ||
import { lazy, Suspense } from 'react'; | ||
|
||
const PlotBase = lazy(() => import('./Plot.js')); | ||
|
||
function Plot(props: React.ComponentProps<typeof PlotBase>): JSX.Element { | ||
return ( | ||
<Suspense fallback={<LoadingOverlay />}> | ||
{/* eslint-disable react/jsx-props-no-spreading */} | ||
<PlotBase {...props} /> | ||
</Suspense> | ||
); | ||
} | ||
|
||
export default Plot; |
This file contains 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
7 changes: 6 additions & 1 deletion
7
packages/components/src/theme/theme-spectrum/theme-spectrum-alias.module.css
This file contains 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
6 changes: 5 additions & 1 deletion
6
packages/components/src/theme/theme-spectrum/theme-spectrum-palette.module.css
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { forwardRef, lazy, Suspense } from 'react'; | ||
import { LoadingOverlay } from '@deephaven/components'; | ||
import type IrisGridType from './IrisGrid'; | ||
import type { IrisGridProps } from './IrisGrid'; | ||
|
||
const IrisGrid = lazy(() => import('./IrisGrid.js')); | ||
|
||
const LazyIrisGrid = forwardRef< | ||
IrisGridType, | ||
JSX.LibraryManagedAttributes<typeof IrisGridType, IrisGridProps> | ||
>( | ||
( | ||
// This creates the correct type to make defaultProps optional | ||
props, | ||
ref | ||
): JSX.Element => ( | ||
<Suspense fallback={<LoadingOverlay />}> | ||
{/* eslint-disable-next-line react/jsx-props-no-spreading */} | ||
<IrisGrid ref={ref} {...props} /> | ||
</Suspense> | ||
) | ||
); | ||
|
||
LazyIrisGrid.displayName = 'LazyIrisGrid'; | ||
|
||
export default LazyIrisGrid; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { test, expect, Request } from '@playwright/test'; | ||
import { openPlot } from './utils'; | ||
|
||
/** | ||
* Checks the size of the response body of a request | ||
* If the response body size is 0, the request is not checked | ||
* This seems to happen for Safari sometimes | ||
* | ||
* @param request The request object. Playwright provides size on the request, not the response | ||
* @param size The minimum size in bytes | ||
*/ | ||
async function expectMinimumResponseSize( | ||
request: Request | undefined, | ||
size: number | ||
) { | ||
if (!request) { | ||
throw new Error('Request is undefined'); | ||
} | ||
|
||
const responseSize = (await request.sizes()).responseBodySize; | ||
|
||
// Safari doesn't seem to provide response size for some requests | ||
if (responseSize > 0) { | ||
expect(responseSize).toBeGreaterThan(size); | ||
} | ||
} | ||
|
||
test('lazy loads plotly', async ({ page }) => { | ||
const requests: Request[] = []; | ||
page.on('request', req => requests.push(req)); | ||
|
||
await page.goto(''); | ||
await page.waitForLoadState('networkidle'); | ||
|
||
expect(requests.some(req => req.url().includes('assets/plotly'))).toBe(false); | ||
|
||
await openPlot(page, 'simple_plot'); | ||
|
||
const plotlyRequest = requests.find(req => | ||
req.url().includes('assets/plotly') | ||
); | ||
expect(plotlyRequest).toBeDefined(); | ||
await expectMinimumResponseSize(plotlyRequest, 300 * 1000); // 300kB | ||
}); | ||
|
||
test('lazy loads mathjax', async ({ page }) => { | ||
const requests: Request[] = []; | ||
page.on('request', req => requests.push(req)); | ||
|
||
await page.goto(''); | ||
await page.waitForLoadState('networkidle'); | ||
|
||
expect(requests.some(req => req.url().includes('assets/mathjax'))).toBe( | ||
false | ||
); | ||
|
||
const controlsButton = page.getByText('Controls'); | ||
await controlsButton.click(); | ||
const markdownButton = page.getByText('Markdown Widget'); | ||
await markdownButton.click(); | ||
|
||
await expect(page.locator('.markdown-panel')).toBeVisible(); | ||
await expect(page.locator('.markdown-panel .loading-spinner')).toHaveCount(0); | ||
|
||
const mathjaxRequest = requests.find(req => | ||
req.url().includes('assets/mathjax') | ||
); | ||
expect(mathjaxRequest).toBeDefined(); | ||
await expectMinimumResponseSize(mathjaxRequest, 500 * 1000); // 500kB | ||
}); |
This file contains 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