Skip to content

Commit

Permalink
remove code for handling undefined that is now useless
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmfern committed Dec 27, 2024
1 parent 909ea90 commit 0b2e02f
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions packages/react-email/src/hooks/use-rendering-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,22 @@ const lastRenderingMetadataPerEmailPath = {} as Record<
*/
export const useRenderingMetadata = (
emailPath: string,
renderingResult: EmailRenderingResult | undefined,
initialRenderingMetadata: EmailRenderingResult | undefined,
renderingResult: EmailRenderingResult,
serverRenderingMetadata: EmailRenderingResult,
): RenderedEmailMetadata | undefined => {
useEffect(() => {
if (!renderingResult) return;

if ('markup' in renderingResult) {
lastRenderingMetadataPerEmailPath[emailPath] = renderingResult;
} else if (
typeof initialRenderingMetadata !== 'undefined' &&
'markup' in initialRenderingMetadata &&
typeof serverRenderingMetadata !== 'undefined' &&
'markup' in serverRenderingMetadata &&
typeof lastRenderingMetadataPerEmailPath[emailPath] === 'undefined'
) {
lastRenderingMetadataPerEmailPath[emailPath] = initialRenderingMetadata;
lastRenderingMetadataPerEmailPath[emailPath] = serverRenderingMetadata;
}
}, [renderingResult, emailPath, initialRenderingMetadata]);

if (renderingResult) {
return 'error' in renderingResult
? lastRenderingMetadataPerEmailPath[emailPath]
: renderingResult;
}
}, [renderingResult, emailPath, serverRenderingMetadata]);

return undefined;
return 'error' in renderingResult
? lastRenderingMetadataPerEmailPath[emailPath]
: renderingResult;
};

0 comments on commit 0b2e02f

Please sign in to comment.