GeezerVison is showing github.com — [Fizz] Various smaller refactors (#27368) · react/react@e520565
File treeExpand file treeCollapse file tree Open diff view settings react-dom-bindings/src/server
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -3717,7 +3717,7 @@ export function writeEndSegment( | 3717 | 3717 | } | 3718 | 3718 |
| 3719 | 3719 | const completeSegmentScript1Full = stringToPrecomputedChunk( | 3720 | | - completeSegmentFunction + ';$RS("', | | 3720 | + completeSegmentFunction + '$RS("', | 3721 | 3721 | ); | 3722 | 3722 | const completeSegmentScript1Partial = stringToPrecomputedChunk('$RS("'); | 3723 | 3723 | const completeSegmentScript2 = stringToPrecomputedChunk('","'); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-server/src/ReactFizzServer.js +43-31Lines changed: 43 additions & 31 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -169,36 +169,40 @@ const REPLAY_SUSPENSE_BOUNDARY = 1; | 169 | 169 | const RESUME_ELEMENT = 2; | 170 | 170 | const RESUME_SLOT = 3; | 171 | 171 |
| 172 | | -type ResumableParentNode = | | 172 | +type ReplaySuspenseBoundary = [ | | 173 | + 1, // REPLAY_SUSPENSE_BOUNDARY | | 174 | + string | null /* name */, | | 175 | + string | number /* key */, | | 176 | + Array<ResumableNode> /* children */, | | 177 | + SuspenseBoundaryID /* id */, | | 178 | +]; | | 179 | + | | 180 | +type ReplayNode = | 173 | 181 | | [ | 174 | 182 | 0, // REPLAY_NODE | 175 | 183 | string | null /* name */, | 176 | 184 | string | number /* key */, | 177 | 185 | Array<ResumableNode> /* children */, | 178 | 186 | ] | 179 | | - | [ | 180 | | - 1, // REPLAY_SUSPENSE_BOUNDARY | 181 | | - string | null /* name */, | 182 | | - string | number /* key */, | 183 | | - Array<ResumableNode> /* children */, | 184 | | - SuspenseBoundaryID, | 185 | | - ]; | 186 | | -type ResumableNode = | 187 | | - | ResumableParentNode | 188 | | - | [ | 189 | | - 2, // RESUME_ELEMENT | 190 | | - string | null /* name */, | 191 | | - string | number /* key */, | 192 | | - number /* segment id */, | 193 | | - ] | 194 | | - | [ | 195 | | - 3, // RESUME_SLOT | 196 | | - number /* index */, | 197 | | - number /* segment id */, | 198 | | - ]; | | 187 | + | ReplaySuspenseBoundary; | | 188 | + | | 189 | +type ResumeElement = [ | | 190 | + 2, // RESUME_ELEMENT | | 191 | + string | null /* name */, | | 192 | + string | number /* key */, | | 193 | + number /* segment id */, | | 194 | +]; | | 195 | + | | 196 | +type ResumeSlot = [ | | 197 | + 3, // RESUME_SLOT | | 198 | + number /* index */, | | 199 | + number /* segment id */, | | 200 | +]; | | 201 | + | | 202 | +type ResumableNode = ReplayNode | ResumeElement | ResumeSlot; | 199 | 203 |
| 200 | 204 | type PostponedHoles = { | 201 | | - workingMap: Map<KeyNode, ResumableParentNode>, | | 205 | + workingMap: Map<KeyNode, ReplayNode>, | 202 | 206 | root: Array<ResumableNode>, | 203 | 207 | }; | 204 | 208 |
| @@ -394,6 +398,7 @@ export function createRequest( | 394 | 398 | request, | 395 | 399 | null, | 396 | 400 | children, | | 401 | + -1, | 397 | 402 | null, | 398 | 403 | rootSegment, | 399 | 404 | abortSet, | @@ -494,6 +499,7 @@ export function resumeRequest( | 494 | 499 | request, | 495 | 500 | null, | 496 | 501 | children, | | 502 | + -1, | 497 | 503 | null, | 498 | 504 | rootSegment, | 499 | 505 | abortSet, | @@ -551,6 +557,7 @@ function createTask( | 551 | 557 | request: Request, | 552 | 558 | thenableState: ThenableState | null, | 553 | 559 | node: ReactNodeList, | | 560 | + childIndex: number, | 554 | 561 | blockedBoundary: Root | SuspenseBoundary, | 555 | 562 | blockedSegment: Segment, | 556 | 563 | abortSet: Set<Task>, | @@ -568,6 +575,7 @@ function createTask( | 568 | 575 | } | 569 | 576 | const task: Task = ({ | 570 | 577 | node, | | 578 | + childIndex, | 571 | 579 | ping: () => pingTask(request, task), | 572 | 580 | blockedBoundary, | 573 | 581 | blockedSegment, | @@ -578,7 +586,6 @@ function createTask( | 578 | 586 | context, | 579 | 587 | treeContext, | 580 | 588 | thenableState, | 581 | | - childIndex: -1, | 582 | 589 | }: any); | 583 | 590 | if (__DEV__) { | 584 | 591 | task.componentStack = null; | @@ -730,6 +737,8 @@ function renderSuspenseBoundary( | 730 | 737 | props: Object, | 731 | 738 | ): void { | 732 | 739 | pushBuiltInComponentStackInDEV(task, 'Suspense'); | | 740 | + | | 741 | + const prevKeyPath = task.keyPath; | 733 | 742 | const parentBoundary = task.blockedBoundary; | 734 | 743 | const parentSegment = task.blockedSegment; | 735 | 744 |
| @@ -791,6 +800,7 @@ function renderSuspenseBoundary( | 791 | 800 | newBoundary.resources, | 792 | 801 | ); | 793 | 802 | } | | 803 | + task.keyPath = keyPath; | 794 | 804 | try { | 795 | 805 | // We use the safe form because we don't handle suspending here. Only error handling. | 796 | 806 | renderNode(request, task, content, -1); | @@ -844,6 +854,7 @@ function renderSuspenseBoundary( | 844 | 854 | } | 845 | 855 | task.blockedBoundary = parentBoundary; | 846 | 856 | task.blockedSegment = parentSegment; | | 857 | + task.keyPath = prevKeyPath; | 847 | 858 | } | 848 | 859 |
| 849 | 860 | // We create suspended task for the fallback because we don't want to actually work | @@ -852,6 +863,7 @@ function renderSuspenseBoundary( | 852 | 863 | request, | 853 | 864 | null, | 854 | 865 | fallback, | | 866 | + -1, | 855 | 867 | parentBoundary, | 856 | 868 | boundarySegment, | 857 | 869 | fallbackAbortSet, | @@ -1938,15 +1950,15 @@ function trackPostpone( | 1938 | 1950 | ); | 1939 | 1951 | } | 1940 | 1952 | const children: Array<ResumableNode> = []; | 1941 | | - const boundaryNode: ResumableParentNode = [ | | 1953 | + const boundaryNode: ReplaySuspenseBoundary = [ | 1942 | 1954 | REPLAY_SUSPENSE_BOUNDARY, | 1943 | 1955 | boundaryKeyPath[1], | 1944 | 1956 | boundaryKeyPath[2], | 1945 | 1957 | children, | 1946 | 1958 | boundary.id, | 1947 | 1959 | ]; | 1948 | 1960 | trackedPostpones.workingMap.set(boundaryKeyPath, boundaryNode); | 1949 | | - addToResumableParent(boundaryNode, boundaryKeyPath[0], trackedPostpones); | | 1961 | + addToReplayParent(boundaryNode, boundaryKeyPath[0], trackedPostpones); | 1950 | 1962 | } | 1951 | 1963 |
| 1952 | 1964 | const keyPath = task.keyPath; | @@ -1964,11 +1976,11 @@ function trackPostpone( | 1964 | 1976 | keyPath[2], | 1965 | 1977 | segment.id, | 1966 | 1978 | ]; | 1967 | | - addToResumableParent(resumableElement, keyPath[0], trackedPostpones); | | 1979 | + addToReplayParent(resumableElement, keyPath[0], trackedPostpones); | 1968 | 1980 | } else { | 1969 | 1981 | // Resume at the slot within the array | 1970 | 1982 | const resumableNode = [RESUME_SLOT, task.childIndex, segment.id]; | 1971 | | - addToResumableParent(resumableNode, keyPath, trackedPostpones); | | 1983 | + addToReplayParent(resumableNode, keyPath, trackedPostpones); | 1972 | 1984 | } | 1973 | 1985 | } | 1974 | 1986 |
| @@ -2023,6 +2035,7 @@ function spawnNewSuspendedTask( | 2023 | 2035 | request, | 2024 | 2036 | thenableState, | 2025 | 2037 | task.node, | | 2038 | + task.childIndex, | 2026 | 2039 | task.blockedBoundary, | 2027 | 2040 | newSegment, | 2028 | 2041 | task.abortSet, | @@ -2032,7 +2045,6 @@ function spawnNewSuspendedTask( | 2032 | 2045 | task.context, | 2033 | 2046 | task.treeContext, | 2034 | 2047 | ); | 2035 | | - newTask.childIndex = task.childIndex; | 2036 | 2048 |
| 2037 | 2049 | if (__DEV__) { | 2038 | 2050 | if (task.componentStack !== null) { | @@ -3072,7 +3084,7 @@ export function getResumableState(request: Request): ResumableState { | 3072 | 3084 | return request.resumableState; | 3073 | 3085 | } | 3074 | 3086 |
| 3075 | | -function addToResumableParent( | | 3087 | +function addToReplayParent( | 3076 | 3088 | node: ResumableNode, | 3077 | 3089 | parentKeyPath: Root | KeyNode, | 3078 | 3090 | trackedPostpones: PostponedHoles, | @@ -3088,9 +3100,9 @@ function addToResumableParent( | 3088 | 3100 | parentKeyPath[1], | 3089 | 3101 | parentKeyPath[2], | 3090 | 3102 | ([]: Array<ResumableNode>), | 3091 | | - ]: ResumableParentNode); | | 3103 | + ]: ReplayNode); | 3092 | 3104 | workingMap.set(parentKeyPath, parentNode); | 3093 | | - addToResumableParent(parentNode, parentKeyPath[0], trackedPostpones); | | 3105 | + addToReplayParent(parentNode, parentKeyPath[0], trackedPostpones); | 3094 | 3106 | } | 3095 | 3107 | parentNode[3].push(node); | 3096 | 3108 | } | |
|