| 1 | /* eslint-disable dot-notation */ |
| 2 | |
| 3 | // Instruction set for the Fizz external runtime |
| 4 | |
| 5 | import { |
| 6 | clientRenderBoundary, |
| 7 | completeBoundary, |
| 8 | completeBoundaryWithStyles, |
| 9 | completeSegment, |
| 10 | listenToFormSubmissionsForReplaying, |
| 11 | revealCompletedBoundaries, |
| 12 | revealCompletedBoundariesWithViewTransitions, |
| 13 | } from './ReactDOMFizzInstructionSetShared'; |
| 14 | |
| 15 | // This is a string so Closure's advanced compilation mode doesn't mangle it. |
| 16 | // These will be renamed to local references by the external-runtime-plugin. |
| 17 | window['$RM'] = new Map(); |
| 18 | window['$RB'] = []; |
| 19 | window['$RX'] = clientRenderBoundary; |
| 20 | window['$RV'] = revealCompletedBoundariesWithViewTransitions.bind( |
| 21 | null, |
| 22 | revealCompletedBoundaries, |
| 23 | ); |
| 24 | window['$RC'] = completeBoundary; |
| 25 | window['$RR'] = completeBoundaryWithStyles; |
| 26 | window['$RS'] = completeSegment; |
| 27 | |
| 28 | listenToFormSubmissionsForReplaying(); |
| 29 | |
| 30 | // Track the paint time of the shell. |
| 31 | const entries = performance.getEntriesByType |
| 32 | ? performance.getEntriesByType('paint') |
| 33 | : []; |
| 34 | if (entries.length > 0) { |
| 35 | // We might have already painted before this external runtime loaded. In that case we |
| 36 | // try to get the first paint from the performance metrics to avoid delaying further |
| 37 | // than necessary. |
| 38 | window['$RT'] = entries[0].startTime; |
| 39 | } else { |
| 40 | // Otherwise we wait for the next rAF for it. |
| 41 | requestAnimationFrame(() => { |
| 42 | window['$RT'] = performance.now(); |
| 43 | }); |
| 44 | } |