use-asset icon indicating copy to clipboard operation
use-asset copied to clipboard

Allow asset hydration

Open lxsmnsyc opened this issue 5 years ago • 2 comments

Some frameworks like Next performs data prefetching in the server-side, providing the initial data for the whole app. Libraries like swr and react-query takes advantage of this by using the prefetched data as the initial cache data and performs the fetch process/cache invalidation only on client-side.

Asset hydration helps because React SSR cannot handle nor does not support Suspense (CM, however, supports this) and since the asset is guaranteed to have an initial data, the component does not have to suspend during SSR and the potentially suspending component can safely present its success UI.

I think something like asset.hydrate(args, data) or useAsset(asset, args, initialData) is a good API. Thoughts?

lxsmnsyc avatar Nov 11 '20 06:11 lxsmnsyc

seems useful, would you want to open a pr for this?

drcmda avatar Nov 11 '20 08:11 drcmda

@drcmda I'm willing to, although I have yet to address some minor issues in the code (e.g. type unsoundness). I'll probably address those on a separate issue

edit: Just saw @dai-shi 's commits, looks like the issues are fixed.

lxsmnsyc avatar Nov 13 '20 15:11 lxsmnsyc