Skip to content

Commit

Permalink
Fix Client components losing state on refetch
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Nov 23, 2020
1 parent 769b13e commit b64032c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,19 @@ export function resolveModelToJSON(
request.pendingChunks++;
const moduleId = request.nextChunkId++;
emitModuleChunk(request, moduleId, moduleMetaData);
if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
// If we're encoding the "type" of an element, we can refer
// to that by a lazy reference instead of directly since React
// knows how to deal with lazy values. This lets us suspend
// on this component rather than its parent until the code has
// loaded.
return serializeByRefID(moduleId);
}

// Removed because this make lazy "type" different between refetches.
// TODO: add this back?

// if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
// // If we're encoding the "type" of an element, we can refer
// // to that by a lazy reference instead of directly since React
// // knows how to deal with lazy values. This lets us suspend
// // on this component rather than its parent until the code has
// // loaded.
// return serializeByRefID(moduleId);
// }

return serializeByValueID(moduleId);
} catch (x) {
request.pendingChunks++;
Expand Down

0 comments on commit b64032c

Please sign in to comment.