store make unexpected extra fetches
Steps to reproduce
When setting data in the cache (from a service worker for example), the store makes extra XHR calls which are useless.
To reproduce, in an HTML page:
<script>
document.addEventListener('DOMContentLoaded', () => {
sibStore.setLocalData({
'@id': "/examples/data/list/skill-1.jsonld",
'related': {
'@id': "/examples/data/list/skill-2.jsonld"
}
}, '/examples/data/list/skill-1.jsonld')
})
</script>
Expected behavior
We expect the store to set the data in the cache, and not to make any calls.
What's happening?
The store fetches /examples/data/list/skill-2.jsonld
.
There is 2 reasons for this:
- After an update or a
setLocalData
, the store gets the nested resources via the proxy, like this:
const resource = store.get("/examples/data/list/skill-1.jsonld");
const nestedProperty = await resource['related']
The proxy then automatically fetches a resource which is incomplete (https://git.startinblox.com/framework/sib-core/blob/0985201eefbc569f059c1c1d39e2888822092822/src/libs/store/store.ts#L503)
- After an update or a
setLocalData
, the store refreshes the nested resources, even if they are not in the cache already: https://git.startinblox.com/framework/sib-core/blob/0985201eefbc569f059c1c1d39e2888822092822/src/libs/store/store.ts#L208-209
Your Environment
- Library version: 0.17
- Targeted application: hubl