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

Display an error message when the service is unreachable #8490

Closed
wants to merge 12 commits into from

Conversation

khuddite
Copy link
Contributor

@khuddite khuddite commented Nov 13, 2024

Fixes #8487

  1. Summary
    We block the rest of the UI if we fail to fetch client config from the back-end for whatever reason. Therefore, a white screen is displayed without any feedback whenever that happens.
    ClientConfigProvider is the component that blocks UI when the client config has not been loaded.

  2. Solution
    It ended up being more changes than I anticipated but those changes were necessary. I removed ClientConfigProvider to unblock the rest of the UI even if the back-end is unreachable. Used enqueueSnackBar to display an error message when the client config failed to load. Used isClientConfigLoaded in a couple of places to ensure no further requests are made if client config fetch fails.

  3. Recording

CleanShot.2024-11-13.at.17.01.03.mp4

Honestly, I am unsure if it's the best way to tackle the issue, but I'd like to receive feedback on this.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR improves error handling when the backend service is unreachable by removing blocking UI behavior and adding clear error messaging.

  • Removed ClientConfigProvider component to prevent UI blocking when client config fails to load
  • Added error snackbar notification in ClientConfigProviderEffect when backend is unreachable
  • Added isClientConfigLoaded check in UserProviderEffect to prevent unnecessary network requests
  • Modified PageChangeEffect to check client config status before tracking analytics
  • Updated test decorators to reflect new non-blocking architecture

6 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 32 to 33
<ClientConfigProviderEffect />
<ClientConfigProvider>
<ChromeExtensionSidecarEffect />
<ChromeExtensionSidecarProvider>
<UserProviderEffect />
<UserProvider>
<AuthProvider>
<ApolloMetadataClientProvider>
<ObjectMetadataItemsProvider>
<PrefetchDataProvider>
<AppThemeProvider>
<SnackBarProvider>
<DialogManagerScope dialogManagerScopeId="dialog-manager">
<DialogManager>
<StrictMode>
<PromiseRejectionEffect />
<GotoHotkeysEffectsProvider />
<PageTitle title={pageTitle} />
<Outlet />
</StrictMode>
</DialogManager>
</DialogManagerScope>
</SnackBarProvider>
</AppThemeProvider>
</PrefetchDataProvider>
<PageChangeEffect />
</ObjectMetadataItemsProvider>
</ApolloMetadataClientProvider>
</AuthProvider>
</UserProvider>
</ChromeExtensionSidecarProvider>
</ClientConfigProvider>
<ChromeExtensionSidecarEffect />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: ClientConfigProviderEffect and ChromeExtensionSidecarEffect may try to make API calls before SnackBarProvider is mounted, potentially losing error messages

Comment on lines 50 to 55
if (error !== undefined) {
enqueueSnackBar('Unable to reach backend', {
variant: SnackBarVariant.Error,
});
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: setIsClientConfigLoaded(false) should be called here to ensure the state accurately reflects the failed load

@@ -90,5 +102,7 @@ export const ClientConfigProviderEffect = () => {
setIsAnalyticsEnabled,
]);

console.log('error: ', error, loading);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: remove console.log before merging to production

Comment on lines 71 to 73
<ClientConfigProviderEffect />
<ClientConfigProvider>
<UserProviderEffect />
<UserProvider>
<ApolloMetadataClientMockedProvider>
<ObjectMetadataItemsProvider>
<FullHeightStorybookLayout>
<HelmetProvider>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
<IconsProvider>
<PrefetchDataProvider>
<Outlet />
</PrefetchDataProvider>
</IconsProvider>
</SnackBarProviderScope>
</HelmetProvider>
</FullHeightStorybookLayout>
</ObjectMetadataItemsProvider>
</ApolloMetadataClientMockedProvider>
</UserProvider>
</ClientConfigProvider>
<UserProviderEffect />
<UserProvider>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: UserProviderEffect depends on client config being loaded, but now runs regardless of client config status. This could cause cascading errors if client config fails

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's causing any issues here

@khuddite khuddite marked this pull request as draft November 13, 2024 22:22
@khuddite khuddite marked this pull request as ready for review November 13, 2024 22:37
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

This PR continues the error handling improvements by implementing comprehensive error capture and display mechanisms across the application.

  • Added PromiseRejectionEffect to catch and display unhandled promise rejections via snackbar
  • Moved ClientConfigProviderEffect after SnackBarProvider in provider hierarchy to ensure error messages are displayed
  • Added error handling for ObjectMetadataItemNotFoundError with specific error message
  • Added Sentry integration placeholder in PromiseRejectionEffect for future error tracking

3 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

});
return;
}
if (isDefined(data?.clientConfig)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider adding an else clause to handle undefined clientConfig case explicitly

@FelixMalfait
Copy link
Member

Thanks a lot!!!
I'm not sure this is the best solution too. @lucasbordeau what do you think? Should we keep this approach?
One thing that I like is that I feel it could improve performance positively by making this query less render-blocking and starting to display more components sooner.
But on the other hand having the ClientConfigProviderEffect so far down the component stack feels wrong as it's almost meant to be "environment variable for the frontend" so something quite generic that's accessible across the code.
Also the tests broke, not sure if it's easy to fix them @khuddite? Maybe let's wait for confirmation from @lucasbordeau to make sure you don't waste time

@FelixMalfait FelixMalfait self-assigned this Nov 15, 2024
@khuddite
Copy link
Contributor Author

khuddite commented Nov 18, 2024

Thanks a lot!!! I'm not sure this is the best solution too. @lucasbordeau what do you think? Should we keep this approach? One thing that I like is that I feel it could improve performance positively by making this query less render-blocking and starting to display more components sooner. But on the other hand having the ClientConfigProviderEffect so far down the component stack feels wrong as it's almost meant to be "environment variable for the frontend" so something quite generic that's accessible across the code. Also the tests broke, not sure if it's easy to fix them @khuddite? Maybe let's wait for confirmation from @lucasbordeau to make sure you don't waste time

Thanks for taking a look at this. I have had the same experience while working on this project. When this happened for the first time to me, I was a bit confused and couldn't quite figure out how to resolve it other than running the npx nx start command again, even when it's just a matter of order in which services run and hard refresh after few secs would resolve the issue. UI provided literally no clues.
I found the updated behavior a much better experience. I don't think these changes would have any other
negative implications, such as decreased performance, other than elevated user experience.

@Bonapara
Copy link
Member

@FelixMalfait
Copy link
Member

@khuddite we discussed it internally and we think it's better not to change the structure like you did but simply reuse GenericErrorFallback and display this if we're not able to load the client config. Your change here can have unintended downstream consequence, clientConfig is something we want to be able to access through pretty much every component.

Do you want us to take care of it or do you want to give it another try?

Thanks!

@khuddite
Copy link
Contributor Author

@khuddite we discussed it internally and we think it's better not to change the structure like you did but simply reuse GenericErrorFallback and display this if we're not able to load the client config. Your change here can have unintended downstream consequence, clientConfig is something we want to be able to access through pretty much every component.

Do you want us to take care of it or do you want to give it another try?

Thanks!

Thanks for providing the direction. Yeah, I've also noticed that something is not quite correct when I saw many storybook tests have failed for different reasons in consequence. And fixing them didn't seem straightforward.

I will give it another try.

@FelixMalfait
Copy link
Member

Great thanks a lot!

martmull and others added 9 commits November 18, 2024 08:52
fixing twentyhq#7375

---------

Co-authored-by: guillim <guillaume@twenty.com>
fix twentyhq#8204
I changed "API keys" to "API values".
Stopped inputting special characters in Select field option keys.

@lucasbordeau please check the changes and tell me if I need to do any
other changes. :)

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
Fixes: twentyhq#8483

Co-authored-by: Félix Malfait <felix@twenty.com>
First step of twentyhq#6868

Adds min.., max.. queries for DATETIME fields
adds min.., max.., avg.., sum.. queries for NUMBER fields 

(count distinct operation and composite fields such as CURRENCY handling
will be dealt with in a future PR)

<img width="1422" alt="Capture d’écran 2024-11-06 à 15 48 46"
src="https://github.com/user-attachments/assets/4bcdece0-ad3e-4536-9720-fe4044a36719">

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
Co-authored-by: Weiko <corentin@twenty.com>
This reverts commit 5c7f48283529ef7644493f73e4967249c463a1a8.
This reverts commit 92ea9a220cf2a9b35958b964700dbe5709fcd756.
…achable"

This reverts commit abccf584d84b6ea44edc613fe04671ada8a3f0e2.
@charlesBochet
Copy link
Member

@khuddite Thanks for the PR! We will review it shortly, in the meantime, could you fix the conflicts so we can test it functionally (sorry, the project is still evolving quite fast!)

@khuddite
Copy link
Contributor Author

@charlesBochet I am so sorry, I should've converted it to a draft. This PR is not ready for review just yet. I am still in the middle of making changes and following the direction provided by @FelixMalfait

@khuddite khuddite marked this pull request as draft November 18, 2024 15:15
@FelixMalfait
Copy link
Member

FelixMalfait commented Nov 18, 2024

@khuddite might be easier if you start from scratch again instead of solving the many conflict? Don't mind if I close this one and you re-open it with the simplied approach we discussed, starting from a fresh main? Thanks a lot!

@khuddite
Copy link
Contributor Author

@khuddite might be easier if you start from scratch again instead of solving the many conflict? Don't mind if I close this one and you re-open it with the simplied approach we discussed? Thanks a lot!

That makes sense, sure go ahead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message when server isn't responding on first page load
9 participants