-
Notifications
You must be signed in to change notification settings - Fork 3.8k
improvement(perf): eight verified cuts to workspace cold-load JavaScript #6996
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
4 commits
Select commit
Hold shift + click to select a range
de6269e
improvement(perf): eight verified cuts to workspace cold-load JavaScript
waleedlatif1 8edeca6
improvement(logs): contain snapshot chunk-load failures and settle th…
waleedlatif1 357d6a2
fix(logs): recover cleanly from snapshot chunk failures
waleedlatif1 6331d1e
fix(logs): preserve snapshot modal while loading
waleedlatif1 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| export { Dashboard } from './dashboard' | ||
| export { LogDetails, LogDetailsContent } from './log-details' | ||
| export { ExecutionSnapshot } from './log-details/components/execution-snapshot' | ||
| export { FileCards } from './log-details/components/file-download' | ||
| export { TraceView } from './log-details/components/trace-view' | ||
| export { LogRowContextMenu } from './log-row-context-menu' |
1 change: 0 additions & 1 deletion
1
...orkspace/[workspaceId]/logs/components/log-details/components/execution-snapshot/index.ts
This file was deleted.
Oops, something went wrong.
116 changes: 116 additions & 0 deletions
116
...eId]/logs/components/log-details/components/execution-snapshot/snapshot-boundary.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,116 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
| import { act, type ReactNode } from 'react' | ||
| import { createRoot, type Root } from 'react-dom/client' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const { mockToastError } = vi.hoisted(() => ({ | ||
| mockToastError: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@sim/emcn', () => ({ | ||
| Loader: () => <span aria-hidden='true' />, | ||
| Modal: ({ | ||
| children, | ||
| open, | ||
| onOpenChange, | ||
| }: { | ||
| children: ReactNode | ||
| open: boolean | ||
| onOpenChange: (open: boolean) => void | ||
| }) => | ||
| open ? ( | ||
| <div> | ||
| {children} | ||
| <button type='button' onClick={() => onOpenChange(false)}> | ||
| Close | ||
| </button> | ||
| </div> | ||
| ) : null, | ||
| ModalBody: ({ children }: { children: ReactNode }) => <div>{children}</div>, | ||
| ModalContent: ({ children }: { children: ReactNode }) => <div>{children}</div>, | ||
| ModalDescription: ({ children }: { children: ReactNode }) => <p>{children}</p>, | ||
| ModalHeader: ({ children }: { children: ReactNode }) => <h2>{children}</h2>, | ||
| toast: { error: mockToastError }, | ||
| })) | ||
|
|
||
| import { | ||
| SnapshotBoundary, | ||
| SnapshotModalFallback, | ||
| } from '@/app/workspace/[workspaceId]/logs/components/log-details/components/execution-snapshot/snapshot-boundary' | ||
|
|
||
| const LOAD_ERROR = new Error('snapshot chunk failed') | ||
|
|
||
| function ThrowingSnapshot() { | ||
| throw LOAD_ERROR | ||
| } | ||
|
|
||
| describe('SnapshotBoundary', () => { | ||
| let container: HTMLDivElement | ||
| let root: Root | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| container = document.createElement('div') | ||
| document.body.appendChild(container) | ||
| act(() => { | ||
| root = createRoot(container) | ||
| }) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| act(() => root.unmount()) | ||
| container.remove() | ||
| }) | ||
|
|
||
| it('contains a background pre-warm failure without notifying or closing', () => { | ||
| const onLoadError = vi.fn() | ||
|
|
||
| act(() => { | ||
| root.render( | ||
| <SnapshotBoundary isOpen={false} onLoadError={onLoadError}> | ||
| <ThrowingSnapshot /> | ||
| </SnapshotBoundary> | ||
| ) | ||
| }) | ||
|
|
||
| expect(container.childNodes).toHaveLength(0) | ||
| expect(mockToastError).not.toHaveBeenCalled() | ||
| expect(onLoadError).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('notifies and closes an explicitly opened snapshot after a load failure', () => { | ||
| const onLoadError = vi.fn() | ||
|
|
||
| act(() => { | ||
| root.render( | ||
| <SnapshotBoundary isOpen onLoadError={onLoadError}> | ||
| <ThrowingSnapshot /> | ||
| </SnapshotBoundary> | ||
| ) | ||
| }) | ||
|
|
||
| expect(container.childNodes).toHaveLength(0) | ||
| expect(mockToastError).toHaveBeenCalledWith( | ||
| 'Could not load the workflow snapshot. Refresh and try again.' | ||
| ) | ||
| expect(onLoadError).toHaveBeenCalledOnce() | ||
| }) | ||
|
|
||
| it('keeps the modal shell visible while the snapshot bundle loads', () => { | ||
| const onClose = vi.fn() | ||
|
|
||
| act(() => { | ||
| root.render(<SnapshotModalFallback isOpen onClose={onClose} />) | ||
| }) | ||
|
|
||
| expect(container.textContent).toContain('Workflow State') | ||
| expect(container.textContent).toContain('Loading run snapshot…') | ||
|
|
||
| const closeButton = container.querySelector('button') | ||
| expect(closeButton).not.toBeNull() | ||
| act(() => closeButton?.click()) | ||
| expect(onClose).toHaveBeenCalledOnce() | ||
| }) | ||
| }) |
101 changes: 101 additions & 0 deletions
101
...kspaceId]/logs/components/log-details/components/execution-snapshot/snapshot-boundary.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,101 @@ | ||
| 'use client' | ||
|
|
||
| import { Component, type ErrorInfo, type ReactNode } from 'react' | ||
| import { | ||
| Loader, | ||
| Modal, | ||
| ModalBody, | ||
| ModalContent, | ||
| ModalDescription, | ||
| ModalHeader, | ||
| toast, | ||
| } from '@sim/emcn' | ||
| import { createLogger } from '@sim/logger' | ||
|
|
||
| const logger = createLogger('ExecutionSnapshotBoundary') | ||
|
|
||
| interface SnapshotBoundaryProps { | ||
| children: ReactNode | ||
| isOpen: boolean | ||
| onLoadError: () => void | ||
| } | ||
|
|
||
| interface SnapshotBoundaryState { | ||
| hasError: boolean | ||
| } | ||
|
|
||
| const reportedErrors = new WeakSet<Error>() | ||
|
|
||
| interface SnapshotModalFallbackProps { | ||
| isOpen: boolean | ||
| onClose: () => void | ||
| } | ||
|
|
||
| export function SnapshotModalFallback({ isOpen, onClose }: SnapshotModalFallbackProps) { | ||
| return ( | ||
| <Modal | ||
| open={isOpen} | ||
| onOpenChange={(open) => { | ||
| if (!open) onClose() | ||
| }} | ||
| > | ||
| <ModalContent size='full' className='flex h-[90vh] flex-col'> | ||
| <ModalHeader>Workflow State</ModalHeader> | ||
| <ModalBody className='!p-0 flex min-h-0 flex-1 items-center justify-center overflow-hidden'> | ||
| <ModalDescription className='sr-only'> | ||
| Loading the workflow state snapshot for this execution | ||
| </ModalDescription> | ||
| <div className='flex items-center gap-2 text-[var(--text-secondary)]'> | ||
| <Loader className='size-[16px]' animate /> | ||
| <span className='text-small'>Loading run snapshot…</span> | ||
| </div> | ||
| </ModalBody> | ||
| </ModalContent> | ||
| </Modal> | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Error boundary for the lazily loaded execution snapshot. | ||
| * | ||
| * `Suspense` handles the pending state of the lazy import but not its | ||
| * rejection — a failed chunk load (deploy skew, offline) would otherwise | ||
| * unwind to the route-level boundary and replace the whole logs page with an | ||
| * error view over an optional modal. Mirrors `PreviewErrorBoundary` in the | ||
| * file viewer: contain, log, degrade. The snapshot is an overlay, so the | ||
| * degraded state renders nothing. Closed snapshots are mounted to pre-warm | ||
| * their chunk and data, so a background failure is logged without interrupting | ||
| * the user. If the user actually opens a failed snapshot, the caller closes | ||
| * the modal state and a toast explains why it did not open. | ||
| * | ||
| * Callers must remount this boundary when the snapshot identity changes and | ||
| * when a pre-warmed snapshot is explicitly opened. Error boundaries reset only | ||
| * via remount; without both transitions, a failed pre-warm would leave the | ||
| * later open action stuck in the already-tripped state. | ||
| */ | ||
| export class SnapshotBoundary extends Component<SnapshotBoundaryProps, SnapshotBoundaryState> { | ||
| public state: SnapshotBoundaryState = { hasError: false } | ||
|
|
||
| public static getDerivedStateFromError(): SnapshotBoundaryState { | ||
| return { hasError: true } | ||
| } | ||
|
|
||
| public componentDidCatch(error: Error, errorInfo: ErrorInfo) { | ||
| if (!reportedErrors.has(error)) { | ||
| reportedErrors.add(error) | ||
| logger.error('Execution snapshot failed to load', { | ||
| error: error.message, | ||
| componentStack: errorInfo.componentStack, | ||
| }) | ||
| } | ||
|
|
||
| if (this.props.isOpen) { | ||
| toast.error('Could not load the workflow snapshot. Refresh and try again.') | ||
| this.props.onLoadError() | ||
| } | ||
| } | ||
|
waleedlatif1 marked this conversation as resolved.
|
||
|
|
||
| public render() { | ||
| return this.state.hasError ? null : this.props.children | ||
| } | ||
| } | ||
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
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.