-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Lazy loading and code splitting #1802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
53f1c59
Plotly lazy loading and code splitting
mattrunyon d9be469
Add loading spinner as fallback
mattrunyon 3227d5b
Split iris-grid
mattrunyon e8cda17
Clean up naming
mattrunyon e6098fb
Fix iris-grid wrapper
mattrunyon 2543cd0
Fix unit test
mattrunyon ad42c10
Merge branch 'main' into code-splitting
mattrunyon 55776a3
Fix CSS specificity and e2e test failure
mattrunyon 1e15296
Address review comments
mattrunyon 8156b79
Add unsaved file from rename
mattrunyon f0ff09f
Address review comments and add e2e test
mattrunyon 4f651ff
Add export type for IrisGridType
mattrunyon c54c079
Address comments about e2e test
mattrunyon 1f860fd
Update comments
mattrunyon 6823ec3
Update one more comment
mattrunyon a506aec
Rename expectMinimumResponseSize
mattrunyon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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 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
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
| 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 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
7 changes: 6 additions & 1 deletion
7
packages/components/src/theme/theme-spectrum/theme-spectrum-alias.module.css
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
6 changes: 5 additions & 1 deletion
6
packages/components/src/theme/theme-spectrum/theme-spectrum-palette.module.css
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
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
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
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
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
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
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
| 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 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
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
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
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
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
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
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
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
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
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
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
| 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 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
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.
Uh oh!
There was an error while loading. Please reload this page.