-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
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
Lines 408 to 429 in a206364
| 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
truein the absence of a returned value (maybe here)Line 196 in a206364
this.serverRender.cache[key] = data
What do you think?
Metadata
Metadata
Assignees
Labels
No labels