[ ] List the proposed play in README linking it to this PR.
[ ] Create a play doc using the PLAY_TEMPLATE
[x] Rough solution
[ ] Finessed solution
[ ] Comprehensive inline comments
[ ] Peer review
[ ] Tests
[ ] Once merged change README link to point to the play doc
Problem
Applications which are rendered on the server as well as client require their data dependencies to be fulfilled during both server and browser execution.
Data dependencies include requests to APIs as well as translations, analytics and manifest data.
It is components that are actually dependent on data, yet our current solutions define the requirements at the route/controller level.
This impacts both developers and end users because defining data dependencies at the route level is impossible to maintain and cannot be optimised.
Solution
The ideal solution:
Ensures components get the data they need
Avoids fetching more data than necessary
Avoids fetching the same data multiple times
Ensures that when components are moved or reused that their data dependencies are still fulfilled
This PR attempts to solve 1, 3 & 4. react-jobs is used to declare data fetching tasks at the component level. Requests for cacheable (non-session) data are made on the server, stored in a LRU cache and passed to the client in the HTML response.
On point 2, it is currenlty assumed that all data from API endpoints will be used. However the solution also needs to solve how to avoid passing the same data in subsequent HTML responses during server-browser rehydration cycles. A separate spike is investigating how to rehydrate client state from local storage alternatively.
The solution will includes a data access object that as well as handling caching can be configured to always pass params required by an API e.g. locale, currency, session token etc.
Checklist
Problem
Applications which are rendered on the server as well as client require their data dependencies to be fulfilled during both server and browser execution.
Data dependencies include requests to APIs as well as translations, analytics and manifest data.
It is components that are actually dependent on data, yet our current solutions define the requirements at the route/controller level.
This impacts both developers and end users because defining data dependencies at the route level is impossible to maintain and cannot be optimised.
Solution
The ideal solution:
This PR attempts to solve 1, 3 & 4. react-jobs is used to declare data fetching tasks at the component level. Requests for cacheable (non-session) data are made on the server, stored in a LRU cache and passed to the client in the HTML response.
On point 2, it is currenlty assumed that all data from API endpoints will be used. However the solution also needs to solve how to avoid passing the same data in subsequent HTML responses during server-browser rehydration cycles. A separate spike is investigating how to rehydrate client state from local storage alternatively.
The solution will includes a data access object that as well as handling caching can be configured to always pass params required by an API e.g. locale, currency, session token etc.
Play doc
Todo