(
request: Request,
parent:
| {+[propertyName: string | number]: ReactClientValue}
| $ReadOnlyArray<ReactClientValue>,
parentPropertyName: string,
clientReference: ClientReference<any>,
)
| 2752 | } |
| 2753 | |
| 2754 | function serializeClientReference( |
| 2755 | request: Request, |
| 2756 | parent: |
| 2757 | | {+[propertyName: string | number]: ReactClientValue} |
| 2758 | | $ReadOnlyArray<ReactClientValue>, |
| 2759 | parentPropertyName: string, |
| 2760 | clientReference: ClientReference<any>, |
| 2761 | ): string { |
| 2762 | const clientReferenceKey: ClientReferenceKey = |
| 2763 | getClientReferenceKey(clientReference); |
| 2764 | const writtenClientReferences = request.writtenClientReferences; |
| 2765 | const existingId = writtenClientReferences.get(clientReferenceKey); |
| 2766 | if (existingId !== undefined) { |
| 2767 | if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') { |
| 2768 | // If we're encoding the "type" of an element, we can refer |
| 2769 | // to that by a lazy reference instead of directly since React |
| 2770 | // knows how to deal with lazy values. This lets us suspend |
| 2771 | // on this component rather than its parent until the code has |
| 2772 | // loaded. |
| 2773 | return serializeLazyID(existingId); |
| 2774 | } |
| 2775 | return serializeByValueID(existingId); |
| 2776 | } |
| 2777 | try { |
| 2778 | const clientReferenceMetadata: ClientReferenceMetadata = |
| 2779 | resolveClientReferenceMetadata(request.bundlerConfig, clientReference); |
| 2780 | request.pendingChunks++; |
| 2781 | const importId = request.nextChunkId++; |
| 2782 | emitImportChunk(request, importId, clientReferenceMetadata, false); |
| 2783 | writtenClientReferences.set(clientReferenceKey, importId); |
| 2784 | if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') { |
| 2785 | // If we're encoding the "type" of an element, we can refer |
| 2786 | // to that by a lazy reference instead of directly since React |
| 2787 | // knows how to deal with lazy values. This lets us suspend |
| 2788 | // on this component rather than its parent until the code has |
| 2789 | // loaded. |
| 2790 | return serializeLazyID(importId); |
| 2791 | } |
| 2792 | return serializeByValueID(importId); |
| 2793 | } catch (x) { |
| 2794 | request.pendingChunks++; |
| 2795 | const errorId = request.nextChunkId++; |
| 2796 | const digest = logRecoverableError(request, x, null); |
| 2797 | emitErrorChunk(request, errorId, digest, x, false, null); |
| 2798 | return serializeByValueID(errorId); |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | function serializeDebugClientReference( |
| 2803 | request: Request, |
no test coverage detected