(
request: Request,
counter: {objectLimit: number},
thenable: Thenable<any>,
)
| 852 | } |
| 853 | |
| 854 | function serializeDebugThenable( |
| 855 | request: Request, |
| 856 | counter: {objectLimit: number}, |
| 857 | thenable: Thenable<any>, |
| 858 | ): string { |
| 859 | // Like serializeThenable but for renderDebugModel |
| 860 | request.pendingDebugChunks++; |
| 861 | const id = request.nextChunkId++; |
| 862 | const ref = serializePromiseID(id); |
| 863 | request.writtenDebugObjects.set(thenable, ref); |
| 864 | |
| 865 | switch (thenable.status) { |
| 866 | case 'fulfilled': { |
| 867 | emitOutlinedDebugModelChunk(request, id, counter, thenable.value); |
| 868 | return ref; |
| 869 | } |
| 870 | case 'rejected': { |
| 871 | const x = thenable.reason; |
| 872 | // We don't log these errors since they didn't actually throw into Flight. |
| 873 | const digest = ''; |
| 874 | emitErrorChunk(request, id, digest, x, true, null); |
| 875 | return ref; |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | if (request.status === ABORTING) { |
| 880 | // Ensure that we have time to emit the halt chunk if we're sync aborting. |
| 881 | emitDebugHaltChunk(request, id); |
| 882 | return ref; |
| 883 | } |
| 884 | |
| 885 | const deferredDebugObjects = request.deferredDebugObjects; |
| 886 | if (deferredDebugObjects !== null) { |
| 887 | // For Promises that are not yet resolved, we always defer them. They are async anyway so it's |
| 888 | // safe to defer them. This also ensures that we don't eagerly call .then() on a Promise that |
| 889 | // otherwise wouldn't have initialized. It also ensures that we don't "handle" a rejection |
| 890 | // that otherwise would have triggered unhandled rejection. |
| 891 | deferredDebugObjects.retained.set(id, (thenable: any)); |
| 892 | const deferredRef = '$Y@' + id.toString(16); |
| 893 | // We can now refer to the deferred object in the future. |
| 894 | request.writtenDebugObjects.set(thenable, deferredRef); |
| 895 | return deferredRef; |
| 896 | } |
| 897 | |
| 898 | let cancelled = false; |
| 899 | |
| 900 | thenable.then( |
| 901 | value => { |
| 902 | if (cancelled) { |
| 903 | return; |
| 904 | } |
| 905 | cancelled = true; |
| 906 | if (request.status === ABORTING) { |
| 907 | emitDebugHaltChunk(request, id); |
| 908 | enqueueFlush(request); |
| 909 | return; |
| 910 | } |
| 911 | emitOutlinedDebugModelChunk(request, id, counter, value); |
no test coverage detected