-
Notifications
You must be signed in to change notification settings - Fork 0
Fix production startup recovery state #122
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
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
44 changes: 44 additions & 0 deletions
44
frontend/src/components/system/StartupErrorBoundary.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,44 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import StartupErrorBoundary from './StartupErrorBoundary'; | ||
|
|
||
| function ThrowError({ message }: { message: string }): never { | ||
| throw new Error(message); | ||
| } | ||
|
|
||
| describe('StartupErrorBoundary', () => { | ||
| let consoleError: ReturnType<typeof vi.spyOn>; | ||
|
|
||
| beforeEach(() => { | ||
| consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| consoleError.mockRestore(); | ||
| }); | ||
|
|
||
| it('explains missing Supabase configuration instead of leaving a blank application frame', () => { | ||
| render( | ||
| <StartupErrorBoundary> | ||
| <ThrowError message="Missing Supabase environment variables. Check your .env file." /> | ||
| </StartupErrorBoundary> | ||
| ); | ||
|
|
||
| expect(screen.getByRole('alert')).toBeInTheDocument(); | ||
| expect(screen.getByRole('heading', { name: /system configuration required/i })).toBeInTheDocument(); | ||
| expect(screen.getByText(/missing a required service configuration/i)).toBeInTheDocument(); | ||
| expect(screen.getByRole('button', { name: /retry startup/i })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows a neutral recovery state for unexpected bootstrap failures', () => { | ||
| render( | ||
| <StartupErrorBoundary> | ||
| <ThrowError message="Unexpected lazy module failure" /> | ||
| </StartupErrorBoundary> | ||
| ); | ||
|
|
||
| expect(screen.getByRole('heading', { name: /system unavailable/i })).toBeInTheDocument(); | ||
| expect(screen.getByText(/could not finish starting/i)).toBeInTheDocument(); | ||
| }); | ||
| }); |
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,66 @@ | ||
| import React from 'react'; | ||
|
|
||
| type StartupErrorBoundaryProps = { | ||
| children: React.ReactNode; | ||
| }; | ||
|
|
||
| type StartupErrorBoundaryState = { | ||
| error: Error | null; | ||
| }; | ||
|
|
||
| function isConfigurationError(error: Error): boolean { | ||
| return /missing supabase environment variables/i.test(error.message); | ||
| } | ||
|
|
||
| /** | ||
| * Protects the React bootstrap from module-load and render failures. | ||
| * | ||
| * App is intentionally lazy loaded from `main.tsx`. This boundary therefore | ||
| * remains available when App's Supabase dependency rejects during import, | ||
| * which would otherwise leave the player on an empty frame. | ||
| */ | ||
| export class StartupErrorBoundary extends React.Component< | ||
| StartupErrorBoundaryProps, | ||
| StartupErrorBoundaryState | ||
| > { | ||
| state: StartupErrorBoundaryState = { error: null }; | ||
|
|
||
| static getDerivedStateFromError(error: Error): StartupErrorBoundaryState { | ||
| return { error }; | ||
| } | ||
|
|
||
| private retry = () => { | ||
| window.location.reload(); | ||
| }; | ||
|
|
||
| render() { | ||
| const { error } = this.state; | ||
|
|
||
| if (!error) { | ||
| return this.props.children; | ||
| } | ||
|
|
||
| const configurationError = isConfigurationError(error); | ||
|
|
||
| return ( | ||
| <main className="startup-error-screen" role="alert" aria-live="assertive"> | ||
| <section className="startup-error-card" aria-labelledby="startup-error-title"> | ||
| <span className="startup-error-eyebrow">DEALT / SLIDE</span> | ||
| <h1 id="startup-error-title"> | ||
| {configurationError ? 'SYSTEM CONFIGURATION REQUIRED' : 'SYSTEM UNAVAILABLE'} | ||
| </h1> | ||
| <p> | ||
| {configurationError | ||
| ? 'This game environment is missing a required service configuration. Please contact the deployment owner or try again after the environment is configured.' | ||
| : 'SLIDE could not finish starting. Please try again. If the problem continues, contact the deployment owner.'} | ||
| </p> | ||
| <button type="button" className="startup-error-retry" onClick={this.retry}> | ||
| RETRY STARTUP | ||
| </button> | ||
| </section> | ||
| </main> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export default StartupErrorBoundary; |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces meaningful production startup and recovery behavior, but the commit does not append a dated entry to
docs/PROJECT_LOG.md; that leaves the repository's required decision and rollback record incomplete. Add an entry describing the new error boundary, recovery behavior, and validation performed.AGENTS.md reference: AGENTS.md:L3-L5
Useful? React with 👍 / 👎.