-
Notifications
You must be signed in to change notification settings - Fork 17
perf(studio): code-split the entry chunk (1,641 kB -> 326 kB) #1100
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
+213
−38
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3b5da2
perf(studio): code-split the entry chunk
marcusds 77fd37f
perf(studio): preload the copilot chat chunk on hover
marcusds 52e6234
refactor(studio): drop the PopoverTrigger prop-order comment
marcusds 08431ff
fix(studio): handle lazy-chunk load failures
marcusds 5c0acbb
Merge branch 'main' into studio-entry-bundle-split/mschwab
marcusds 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
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
68 changes: 68 additions & 0 deletions
68
web/packages/studio/src/routes/agents/CopilotChatRoute/ChatThreadErrorBoundary.test.tsx
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,68 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { ChatThreadErrorBoundary } from '@studio/routes/agents/CopilotChatRoute/ChatThreadErrorBoundary'; | ||
| import { TestProviders } from '@studio/tests/util/TestProviders'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { MemoryRouter } from 'react-router'; | ||
|
|
||
| const Boom = ({ shouldThrow }: { shouldThrow: boolean }) => { | ||
| if (shouldThrow) throw new Error('Failed to fetch dynamically imported module'); | ||
| return <div data-testid="chat-thread" />; | ||
| }; | ||
|
|
||
| const renderBoundary = (shouldThrow: boolean, onRetry = vi.fn()) => | ||
| render( | ||
| <TestProviders> | ||
| <MemoryRouter> | ||
| <ChatThreadErrorBoundary onRetry={onRetry}> | ||
| <Boom shouldThrow={shouldThrow} /> | ||
| </ChatThreadErrorBoundary> | ||
| </MemoryRouter> | ||
| </TestProviders> | ||
| ); | ||
|
|
||
| describe('ChatThreadErrorBoundary', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.spyOn(console, 'error').mockImplementation(() => undefined); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('renders children when nothing throws', () => { | ||
| renderBoundary(false); | ||
|
|
||
| expect(screen.getByTestId('chat-thread')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders the failure message instead of unwinding when the chunk fails to load', () => { | ||
| renderBoundary(true); | ||
|
|
||
| expect(screen.getByText('Chat failed to load')).toBeInTheDocument(); | ||
| expect(screen.queryByTestId('chat-thread')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('clears the error and calls onRetry when Try Again is clicked', async () => { | ||
| const user = userEvent.setup(); | ||
| const onRetry = vi.fn(); | ||
| const { rerender } = renderBoundary(true, onRetry); | ||
|
|
||
| rerender( | ||
| <TestProviders> | ||
| <MemoryRouter> | ||
| <ChatThreadErrorBoundary onRetry={onRetry}> | ||
| <Boom shouldThrow={false} /> | ||
| </ChatThreadErrorBoundary> | ||
| </MemoryRouter> | ||
| </TestProviders> | ||
| ); | ||
| await user.click(screen.getByRole('button', { name: /try again/i })); | ||
|
|
||
| expect(onRetry).toHaveBeenCalledOnce(); | ||
| expect(screen.getByTestId('chat-thread')).toBeInTheDocument(); | ||
| }); | ||
| }); |
54 changes: 54 additions & 0 deletions
54
web/packages/studio/src/routes/agents/CopilotChatRoute/ChatThreadErrorBoundary.tsx
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,54 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { ErrorMessage } from '@nemo/common/src/components/ErrorMessage'; | ||
| import { Button } from '@nvidia/foundations-react-core'; | ||
| import { logger } from '@studio/util/logger'; | ||
| import { Component, type ErrorInfo, type ReactNode } from 'react'; | ||
|
|
||
| interface ChatThreadErrorBoundaryProps { | ||
| onRetry: () => void; | ||
| children: ReactNode; | ||
| } | ||
|
|
||
| interface ChatThreadErrorBoundaryState { | ||
| error: Error | null; | ||
| } | ||
|
|
||
| // A failed chunk load throws during render; without this it unwinds to the root | ||
| // and blanks all of Studio, not just the pop-out. | ||
| export class ChatThreadErrorBoundary extends Component< | ||
| ChatThreadErrorBoundaryProps, | ||
| ChatThreadErrorBoundaryState | ||
| > { | ||
| state: ChatThreadErrorBoundaryState = { error: null }; | ||
|
|
||
| static getDerivedStateFromError(error: Error): ChatThreadErrorBoundaryState { | ||
| return { error }; | ||
| } | ||
|
|
||
| componentDidCatch(error: Error, info: ErrorInfo): void { | ||
| logger.error(`Copilot chat thread failed to render: ${error.message}`, info.componentStack); | ||
| } | ||
|
|
||
| private retry = (): void => { | ||
| this.setState({ error: null }); | ||
| this.props.onRetry(); | ||
| }; | ||
|
|
||
| render(): ReactNode { | ||
| if (!this.state.error) return this.props.children; | ||
|
|
||
| return ( | ||
| <ErrorMessage | ||
| header="Chat failed to load" | ||
| message="Check your connection and try again." | ||
| slotFooter={ | ||
| <Button kind="secondary" onClick={this.retry}> | ||
| Try Again | ||
| </Button> | ||
| } | ||
| /> | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.