million
million copied to clipboard
feat: Next.js support
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like A clear and concise description of what you want to happen.
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context Add any other context or screenshots about the feature request here.
Some references, and also a very naive TODO (TBC):
- [ ] Compatible SSR method
- [ ]
renderToString
- [ ]
renderToPipeableStream
- [ ]
renderToReadableStream
- [ ]
- [ ] Fast refresh
- [ ] Next.js plugin
- See: next-plugin-preact: https://github.com/preactjs/next-plugin-preact
Also, I think we should support renderToReadableStream
- it's the equivalent of renderToPipeableStream
but for the browser, Deno and edge environments (like Deno Deploy, Cloudflare Workers, Lagon...)
Also, I think we should support
renderToReadableStream
- it's the equivalent ofrenderToPipeableStream
but for the browser, Deno and edge environments (like Deno Deploy, Cloudflare Workers, Lagon...)
Nice catch!
And actually, you are also the collaborator of the repo. Feel free to update the existing TODO with your ideas!
I think renderToString is already implemented in the React module:
https://github.com/aidenybai/million/blob/21644e4871fcd67d818f7f4007f74c8713e34bdf/packages/react/exports/server.ts#L3
renderToPipeableStream should not be that hard to make:
https://github.com/aidenybai/million/blob/dec80d0af168851541673a0317653422800baea7/packages/utils/index.ts#L103
In that point of the flow, we already know what the tag and attributes are, no need to wait for all the children to send that (Body, I'm looking at u)... Same for the children, the first children can already be written to the stream when its tag & attributes are done.
Fast refresh would probably look like the Prefresh package for NextJS
Preact and Million have different purposes, Million has a compiler that would probably need to be attached to a NextJS Webpack Build Hook, it would probably be better to create a MillionJS Webpack plugin first then.