fix: nextjs ui throws exception on error ts file #208
Merged
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.
fix: Next.js UI throws exception on
error.ts
fileOccasionally (not all the time), whenever I start up the local frontend full stack Next.js webapp, and then attempt to load the frontend UI after the Next.js servers are up and ready, the browser displays an exception thrown by Next.js.
The exception which is occasionally thrown, throws with the error message
Attempted to call getErrorMessage() from the server, but getErrorMessage is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a client component.
.💡 It seems that the
error.ts
file from which thegetErrorMessage()
function is defined conflicts with the reserved Next.js app router keyword forerror.tsx
components, and so Next.js (mistakenly) assumeserror.ts
is client component file, and hence whyuse client
was placed at the top of theerror.ts
file in the first place to overcome the initial error. However, in hindsight this is not the correct solution as the function should be called on the server-side, and so the solution is to instead renameerror.ts
toerrors.ts
, which also makes more logical sense, and can be extended with additional error handling functions in future.This change resolves issue #207.
Related Issue
#207
Description
error.ts
toerrors.ts
to avoid Next.js reserved keyword conflict forError.tsx
boundary client component files.errors.ts
file"use client";
declaration in renamederrors.ts
file, to correctly allow the functions defined within to be called on the server.Type
Proposed Changes
error.ts
errors.ts
third-party-services.tsx
useGlobalStore.ts
Screenshots / Code Snippets (if applicable)
Exception message rendered on the frontend UI of the full stack Next.js web app.
A separate and different exception message thrown by Next.js before further refactoring to remove
"use client";
declaration on the previously incorrectly namederror.ts
file.How to Test
Please follow steps outlined in issue #207
Checklist
Additional Information
N/A