ethanniser / the-beth-stack

An opinionated hypermedia-driven architecture for building web apps
MIT License
838 stars 83 forks source link

feat: Improve type safety, error handling, and resource management in rendering functions #21

Closed 0PrashantYadav0 closed 2 months ago

0PrashantYadav0 commented 2 months ago

Description:

This commit introduces several improvements to the rendering functions to enhance type safety, error handling, and resource management. The changes include:

  1. Type Safety: Ensured that the lazyHtml function is correctly typed to return a Promise<JSX.Element>.
  2. Error Handling: Added try-catch blocks to handle errors more gracefully and provide meaningful error messages in both renderToString and renderToStringResponse functions.
  3. Resource Management: Implemented a cancel method in the ReadableStream to handle stream cancellation properly.
  4. Concurrency Control: Managed the stream controller more effectively, ensuring that errors are handled within the promise chain in the renderToStream function.
  5. Validation: Added basic validation and error messages to ensure that the functions behave as expected.

These changes make the code more robust, safer, and easier to maintain, improving the overall reliability of the rendering process.