Skip to content
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

feat(error): set error boundary for first renders #951

Merged
merged 1 commit into from
Apr 14, 2023

Conversation

tthvo
Copy link
Member

@tthvo tthvo commented Apr 13, 2023

Welcome to Cryostat! 👋

Before contributing, make sure you have:

  • Read the contributing guidelines
  • Linked a relevant issue which this PR resolves
  • Linked any other relevant issues, PR's, or documentation, if any
  • Resolved all conflicts, if any
  • Rebased your branch PR on top of the latest upstream main branch
  • Attached at least one of the following labels to the PR: [chore, ci, docs, feat, fix, test]
  • Signed the last commit: git commit --amend --signoff

Related to: #950

Description of the change:

Add an error boundary around component that renders the main container view. Though, this won't completely fix the issue because we need consider more granular handling.

Note: this applies for first render. If later one child components build fail, no error views will be shown.

Also bear in mind that try/catch blocks won't work on all cases.
If a component deep in the hierarchy tries to updates and fails, the try/catch block in one of the parents won't work -- > ? because it isn't necessarily updating together with the child.

Motivation for the change:

See #950. This applies to first renders to that errors are caught early.

How to manually test:

  1. Run CRYOSTAT_IMAGE=quay.io... sh smoketest.sh...
  2. Try:
diff --git a/src/app/Dashboard/Dashboard.tsx b/src/app/Dashboard/Dashboard.tsx
index 6dffda0c..cdd0e35d 100644
--- a/src/app/Dashboard/Dashboard.tsx
+++ b/src/app/Dashboard/Dashboard.tsx
@@ -267,6 +267,7 @@ export const getDashboardCards: (featureLevel?: FeatureLevel) => DashboardCardDe
 export interface DashboardComponentProps {}
 
 export const Dashboard: React.FC<DashboardComponentProps> = (_) => {
+  throw new Error('Somehow the dashboard cannot be rendered');
   const history = useHistory();
   const serviceContext = React.useContext(ServiceContext);
   const dispatch = useDispatch<StateDispatch>();

Screenshots

Light Theme Dark Theme
Screenshot from 2023-04-13 17-11-56 Screenshot from 2023-04-13 17-12-54

@tthvo tthvo added the feat New feature or request label Apr 13, 2023
@tthvo tthvo requested review from andrewazores and maxcao13 April 13, 2023 21:12
@mergify mergify bot added the safe-to-test label Apr 13, 2023
@github-actions
Copy link

Test image available:

CRYOSTAT_IMAGE=ghcr.io/cryostatio/cryostat-web:pr-951-fb7eff6433cc982cf3be6e18d1b13328e1872195 sh smoketest.sh

@github-actions
Copy link

Test image available:

CRYOSTAT_IMAGE=ghcr.io/cryostatio/cryostat-web:pr-951-f83cebee471a9386c603e0c9c8d4dd4d2190504e sh smoketest.sh

@tthvo
Copy link
Member Author

tthvo commented Apr 13, 2023

Routing still works fine thanks to route having a distinct key (causing its component tree to unmounted). This allows the ErrorBoundary to start with a fresh state.

I think its an important note for later implementation of error boundaries that needs updating -> use key prop.

@tthvo tthvo changed the title feat(error): set error boundary feat(error): set error boundary for first renders Apr 13, 2023
@andrewazores andrewazores merged commit ce47357 into cryostatio:main Apr 14, 2023
@tthvo tthvo deleted the error-boundary branch April 14, 2023 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request safe-to-test
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants