( this: any => Promise<any>, identifierPrefix: string, )
| 941 | } |
| 942 | |
| 943 | function defaultEncodeFormAction( |
| 944 | this: any => Promise<any>, |
| 945 | identifierPrefix: string, |
| 946 | ): ReactCustomFormAction { |
| 947 | const referenceClosure = knownServerReferences.get(this); |
| 948 | if (!referenceClosure) { |
| 949 | throw new Error( |
| 950 | 'Tried to encode a Server Action from a different instance than the encoder is from. ' + |
| 951 | 'This is a bug in React.', |
| 952 | ); |
| 953 | } |
| 954 | let data: null | FormData = null; |
| 955 | let name; |
| 956 | const boundPromise = referenceClosure.bound; |
| 957 | if (boundPromise !== null) { |
| 958 | let thenable = boundCache.get(referenceClosure); |
| 959 | if (!thenable) { |
| 960 | const {id, bound} = referenceClosure; |
| 961 | thenable = encodeFormData({id, bound}); |
| 962 | boundCache.set(referenceClosure, thenable); |
| 963 | } |
| 964 | if (thenable.status === 'rejected') { |
| 965 | throw thenable.reason; |
| 966 | } else if (thenable.status !== 'fulfilled') { |
| 967 | throw thenable; |
| 968 | } |
| 969 | const encodedFormData = thenable.value; |
| 970 | // This is hacky but we need the identifier prefix to be added to |
| 971 | // all fields but the suspense cache would break since we might get |
| 972 | // a new identifier each time. So we just append it at the end instead. |
| 973 | const prefixedData = new FormData(); |
| 974 | // $FlowFixMe[prop-missing] |
| 975 | encodedFormData.forEach((value: string | File, key: string) => { |
| 976 | // $FlowFixMe[incompatible-call] |
| 977 | prefixedData.append('$ACTION_' + identifierPrefix + ':' + key, value); |
| 978 | }); |
| 979 | data = prefixedData; |
| 980 | // We encode the name of the prefix containing the data. |
| 981 | name = '$ACTION_REF_' + identifierPrefix; |
| 982 | } else { |
| 983 | // This is the simple case so we can just encode the ID. |
| 984 | name = '$ACTION_ID_' + referenceClosure.id; |
| 985 | } |
| 986 | return { |
| 987 | name: name, |
| 988 | method: 'POST', |
| 989 | encType: 'multipart/form-data', |
| 990 | data: data, |
| 991 | }; |
| 992 | } |
| 993 | |
| 994 | function customEncodeFormAction( |
| 995 | reference: any => Promise<any>, |
nothing calls this directly
no test coverage detected