Fix Snackbar crashing the whole app (#15774)
This PR fixes a crash of the app when a Snackbar tries to render an object. <img width="3002" height="754" alt="image" src="https://github.com/user-attachments/assets/988f97eb-5c8a-44f8-ac8e-e2953b872bac" /> What happened : the backend sent a MessageDescriptor in `extensions.userFriendlyMessage` while it should have sent a translated string. But it is a problem that the Snackbar can end up rendering objects and crashing the whole app because it is a the highest level in the tree. So this PR hardens many points to avoid future bugs : - Sanitize what is rendered by the Snackbar to avoid any crash - Translate any MessageDescriptor object that could end up in the frontend - Fix the places in the backend where a MessageDescriptor wasn't translated and sent directly to the frontend in `use-graphql-error-handler.hook.ts` Fixes https://github.com/twentyhq/twenty/issues/15685 Fixes https://github.com/twentyhq/core-team-issues/issues/1869
This commit is contained in:
+10
-2
@@ -248,6 +248,9 @@ export const useGraphQLErrorHandlerHook = <
|
||||
onValidate: ({ context, validateFn, params: { documentAST, schema } }) => {
|
||||
const errors = validateFn(schema, documentAST);
|
||||
|
||||
const userLocale = context.req.locale ?? SOURCE_LOCALE;
|
||||
const i18n = options.i18nService.getI18nInstance(userLocale);
|
||||
|
||||
if (Array.isArray(errors) && errors.length > 0) {
|
||||
const headers = context.req.headers;
|
||||
const currentMetadataVersion = context.req.workspaceMetadataVersion;
|
||||
@@ -267,9 +270,12 @@ export const useGraphQLErrorHandlerHook = <
|
||||
options.metricsService.incrementCounter({
|
||||
key: MetricsKeys.SchemaVersionMismatch,
|
||||
});
|
||||
|
||||
throw new GraphQLError(SCHEMA_MISMATCH_ERROR, {
|
||||
extensions: {
|
||||
userFriendlyMessage: msg`Your workspace has been updated with a new data model. Please refresh the page.`,
|
||||
userFriendlyMessage: i18n._(
|
||||
msg`Your workspace has been updated with a new data model. Please refresh the page.`,
|
||||
),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -297,7 +303,9 @@ export const useGraphQLErrorHandlerHook = <
|
||||
throw new GraphQLError(APP_VERSION_MISMATCH_ERROR, {
|
||||
extensions: {
|
||||
code: APP_VERSION_MISMATCH_CODE,
|
||||
userFriendlyMessage: msg`Your app version is out of date. Please refresh the page to continue.`,
|
||||
userFriendlyMessage: i18n._(
|
||||
msg`Your app version is out of date. Please refresh the page to continue.`,
|
||||
),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user