You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Currently, error handling is somewhat cumbersome to set up. It needs to be set up both in i18n.ts as well as NextIntlClientProvider to cover both Server- as well as Client Components.
Most configuration from i18n.ts can automatically be inherited by Client Components, but for onError and getMessageFallback this is not the case since functions aren't serializable. Therefore this requires workaround (see e.g. #1226).
Ideally, we'd let users register error handling once and use it across a whole app without workarounds (regardless of RSC/SSR/CSR).
Describe the solution you'd like
If Next.js would allow client-side instrumentation, we could use instrumentation.ts for this use case. This would be the preferred solution from my perspective.
// instrumentation.tsimport{onError,configureMessageFallback,IntlErrorCode}from'next-intl';// Called for both `react-server` as well as `react-client`exportasyncfunctionregister(){// Called when an error is encountered during formattingonError((error)=>{if(error.code===IntlErrorCode.MISSING_MESSAGE){// Missing translations are expected and should only log an errorconsole.error(error);}else{// Other errors indicate a bug in the app and should be reportedreportToErrorTracking(error);}});// Called to provide a fallback message when formatting has failedconfigureMessageFallback(({namespace, key, error})=>{constpath=[namespace,key].filter((part)=>part!=null).join('.');if(error.code===IntlErrorCode.MISSING_MESSAGE){returnpath+' (fallback)';}else{returnpath+' (formatting error)';}});}
Implementation-wise we'd likely write to a global store if these functions are called in order to register the handler.
Describe alternatives you've considered
Alternatively, we could explore automatically creating an onError server action that can be serialized across the network. This wouldn't work for getMessageFallback though.
Is your feature request related to a problem? Please describe.
Currently, error handling is somewhat cumbersome to set up. It needs to be set up both in
i18n.ts
as well asNextIntlClientProvider
to cover both Server- as well as Client Components.Most configuration from
i18n.ts
can automatically be inherited by Client Components, but foronError
andgetMessageFallback
this is not the case since functions aren't serializable. Therefore this requires workaround (see e.g. #1226).Ideally, we'd let users register error handling once and use it across a whole app without workarounds (regardless of RSC/SSR/CSR).
Describe the solution you'd like
If Next.js would allow client-side instrumentation, we could use
instrumentation.ts
for this use case. This would be the preferred solution from my perspective.Implementation-wise we'd likely write to a global store if these functions are called in order to register the handler.
Describe alternatives you've considered
Alternatively, we could explore automatically creating an
onError
server action that can be serialized across the network. This wouldn't work forgetMessageFallback
though.(this issue was created after working on a first draft on
feat/error-instrumentation
)The text was updated successfully, but these errors were encountered: