atlassian-labs / react-resource-router

Configuration driven routing solution for React SPAs that managesĀ route matching, data fetching and progressive rendering
https://atlassian-labs.github.io/react-resource-router
Apache License 2.0
202 stars 28 forks source link

Async resource definition #77

Closed theKashey closed 3 years ago

theKashey commented 3 years ago

Feature request

Details

Right now the only way to code split resource logic is to implement getDataLoader for a resource, while resources are more or less static property on the route definition.

While getDataLoader seems to be the correct way of doing it - it allows some "already loaded resources" to act sooner - it creates some over complications if has to be compulsorily used, and in our case it is.

Proposal

What is solves

In feature request is not changing anything for the end customer, however makes life of a developer a little easier, decreasing the initial bundle size as well by making it easier to defer resources without any extra code written.

albertogasparin commented 3 years ago

This is an interesting idea. Needs some spiking as not entirely sure of the implications if we cannot immediately know the type and the getKey function. I'm especially thinking about hydration from SSR, where we pass the state directly to the router and expect useResource hooks to immediately render with data šŸ¤”

theKashey commented 3 years ago

The resource chunk existence before the application start sounds not like a big problem for code splitting, however in this case it will be loaded with the full dataLoader as well, bringing more code than required initially. Quite far from the perfect.

Sounds like writting a little more code is still a better idea.

albertogasparin commented 3 years ago

I'll close this issue for now, if we have better ideas for the future happy to reopen :)