Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazily stream #1

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

thetutlage
Copy link

Okay, so let me try to explain the changes.

  • Instead of streaming right away when the jsx.render method is called, we keep reference of the component and its props under the ctx.response.lazyBody array.
  • After AdonisJS is finished with the middleware, controller, and exception handler lifecycle, it will automatically call the ctx.response.writerMethod method, which is set of writeJSX.
  • We write the actual logic of rendering the component to a string or stream within the writeJSX.

This way, the streaming is deferred until the lifecycle of a request is completed. The behavior is same as the response.send method. https://github.com/adonisjs/http-server/blob/develop/src/Response/index.ts#L734


However, I have noticed that the jsx.render method has two responsibilities right now. It can render a component to HTML without sending it in response and also it can send it as a response.

I will recommend having a different methods for both use cases.

Lemme know if you have questions

@bitkidd bitkidd merged commit 718a914 into bitkidd:feature/streaming Oct 25, 2023
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants