Streamed Deferred Props #1887
Closed
nick-potts
started this conversation in
Ideas
Replies: 2 comments
-
Or perhaps a cleaner solution is that CSR only apps run like normal and automatically fetch deferred props after load, whereas the Streamed Server implementation uses the whole shebang. |
Beta Was this translation helpful? Give feedback.
0 replies
-
After digging through the internals, I can see that supporting |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been wondering what Promises would look like as props in Inertia, and I have a partial solution so far. I think this general idea would help move Inertia towards a place where it's more ready for some of the newer JS concepts like React/Vue Suspense. It'd also hand the control over to the developer in terms of how fast a page can be loaded. If there's any sort of heavy function that needs calling, this could instead be deferred and and the frontend could handle the wait, instead of blocking the entire page navigation.
In terms of what it would look like, I'm thinking end goal you'd be able to do something like this
Then on the client side, the data would look like this
Then it'd be trivial to use something like React Suspense
Obviously this would require a fairly different setup to what is currently implemented.
On the PHP side, things can get a bit tricky and there's a few ways of tackling it. I was initially thinking that if there's a deferred prop, it could get passed with a flag indicating so:
Then there's probably two ways to tackle it. First would be the boring route, where inertia does a second request and this data can be streamed in via json:
The second, more exciting way, would be to do the entire thing in one response. Not sure how this would work, but I'd imagine you resolve each prop and fire an event Inertia can listen for, and that would allow the promise to get resolved:
With subsequent page loads, things are far more simple and it would just be a matter of flushing the page props, then each deferred prop out.
I'd also like to see an adapter of some sort for the deferred props. Basically allow the user to provide different strategies for how the ordering of the prop data is rendered out. This would allow for someone to wait for all deferred prop data in one go. Or each prop sequentially, or each prop but in some sort of specified order. Or in my case, I'd like to run each prop resolver using ReactPhp's async function and resolve it with whatever comes back first.
This would handle the CSR case, and then for server it'd require a new server that's different to the SSR server, as it'd need to use the renderToPipeableStream.
Beta Was this translation helpful? Give feedback.
All reactions