Upgrading to v2 and curious about how frontloadMeta.pending works. I have noticed that when nothing is returned from the useFrontload function, there is nothing in the frontloadServerRender.data. And if I'm reading this right
|
const frontloadState = React.useContext(FrontloadContext)! |
|
const serverRendered = frontloadState.isFirstRender() |
|
const pendingInitial = serverRendered |
|
? !frontloadState.hasFrontloadRunOnServer(key) |
|
: true |
|
const data = serverRendered |
|
? frontloadState.getFrontloadServerRenderedData(key) |
|
: undefined |
|
const error = !!data?._____FRONTLOAD_____isServerRenderError |
|
|
|
const [state, setState] = React.useState<{ |
|
data: T |
|
frontloadMeta: FrontloadMeta |
|
}>({ |
|
data, |
|
frontloadMeta: { |
|
serverRendered, |
|
pending: pendingInitial, |
|
done: !pendingInitial, |
|
error, |
|
}, |
|
}) |
it uses the keys as an indicator for whether frontload has run or not.
Here's an example of a redux thunk that doesn't need to return anything, because it is handled in the redux store.
useFrontload('ArticleListContainer', async () => {
await dispatch(fetchAllArticles());
});
So if nothing is returned, it seems like frontloadMeta.pending is always true.
By adding a simple return true
useFrontload('ArticleListContainer', async () => {
await dispatch(fetchAllArticles());
return true;
});
frontloadMeta.pending works as expected.
It seems like the options are to either:
- Require/recommend that people return something from every useFrontload function, update the docs to include that.
- Return something like
true in the absence of a returned value (maybe here
|
this.serverRender.cache[key] = data |
)
What do you think?
Upgrading to v2 and curious about how frontloadMeta.pending works. I have noticed that when nothing is returned from the useFrontload function, there is nothing in the frontloadServerRender.data. And if I'm reading this right
react-frontload/src/index.tsx
Lines 408 to 429 in a206364
it uses the keys as an indicator for whether frontload has run or not.
Here's an example of a redux thunk that doesn't need to return anything, because it is handled in the redux store.
So if nothing is returned, it seems like
frontloadMeta.pendingis always true.By adding a simple
return truefrontloadMeta.pendingworks as expected.It seems like the options are to either:
truein the absence of a returned value (maybe herereact-frontload/src/index.tsx
Line 196 in a206364
What do you think?