Merge remote-tracking branch 'origin/main' into fix/r9-form-and-primitives
This commit is contained in:
@@ -53,11 +53,17 @@ export type ApplicationResult<Value> = Result<Value>;
|
||||
|
||||
class ApplicationQueryError extends Error {
|
||||
readonly failure: AppFailure;
|
||||
/**
|
||||
* 1112/01-04. What the cache diagnostics record (`safeErrorKind` reads
|
||||
* `kind` first): the failure's kind, not one name for every failure.
|
||||
*/
|
||||
readonly kind: AppFailure["kind"];
|
||||
|
||||
constructor(failure: AppFailure) {
|
||||
super(failure.kind);
|
||||
this.name = "ApplicationQueryError";
|
||||
this.failure = failure;
|
||||
this.kind = failure.kind;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +106,6 @@ export function useApplicationQuery<Value>(
|
||||
"definitionId" in options ? options.definitionId : "APPLICATION_QUERY";
|
||||
const invalidation =
|
||||
"invalidation" in options ? options.invalidation : undefined;
|
||||
const [staleFailure, setStaleFailure] = useState(false);
|
||||
useEffect(() => {
|
||||
identity?.acquire();
|
||||
return () => identity?.release();
|
||||
@@ -170,9 +175,10 @@ export function useApplicationQuery<Value>(
|
||||
throw new DOMException("Query cancelled", "AbortError");
|
||||
}
|
||||
if (error instanceof ApplicationQueryError) throw error;
|
||||
// 1112/01-04. The definition it came from, as the other failures here.
|
||||
throw new ApplicationQueryError(
|
||||
normalizeUnknownFailure(error, {
|
||||
operationId: "APPLICATION_QUERY",
|
||||
operationId: queryDefinitionId,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
@@ -181,17 +187,13 @@ export function useApplicationQuery<Value>(
|
||||
},
|
||||
});
|
||||
const hasData = query.data !== undefined && query.data !== null;
|
||||
|
||||
useEffect(() => {
|
||||
if (query.isError && hasData) {
|
||||
setStaleFailure(true);
|
||||
} else if (query.isSuccess && !query.isFetching) {
|
||||
setStaleFailure(false);
|
||||
}
|
||||
}, [hasData, query.isError, query.isFetching, query.isSuccess]);
|
||||
// 1112/01-05. Read while rendering: the data is stale because the last
|
||||
// fetch failed, and no fetch runs now. A retry that is running shows as
|
||||
// refreshing; copied into state by an effect, the old failure came back
|
||||
// over the retry's reset.
|
||||
const staleFailure = query.isError && hasData && !query.isFetching;
|
||||
|
||||
const retry = useCallback(async () => {
|
||||
setStaleFailure(false);
|
||||
await query.refetch({ cancelRefetch: false });
|
||||
}, [query]);
|
||||
|
||||
@@ -375,6 +377,12 @@ export function useApplicationMutation<Input, Value>(
|
||||
"definitionId" in options
|
||||
? options.definitionId ?? "LEGACY_MUTATION"
|
||||
: "LEGACY_MUTATION";
|
||||
// 1112/01-04. An unexpected throw names the mutation definition it came
|
||||
// from; a legacy mutation without one keeps the generic name.
|
||||
const failureOperationId =
|
||||
"definitionId" in options && options.definitionId
|
||||
? options.definitionId
|
||||
: "APPLICATION_MUTATION";
|
||||
const definitionVersion =
|
||||
"definitionVersion" in options ? options.definitionVersion : 0;
|
||||
const duplicatePolicy =
|
||||
@@ -708,7 +716,7 @@ export function useApplicationMutation<Input, Value>(
|
||||
error instanceof ApplicationQueryError
|
||||
? error.failure
|
||||
: normalizeUnknownFailure(error, {
|
||||
operationId: "APPLICATION_MUTATION",
|
||||
operationId: failureOperationId,
|
||||
});
|
||||
const failure = mutationFailureWithEffect(reportedFailure);
|
||||
switch (failure.effect) {
|
||||
@@ -765,7 +773,7 @@ export function useApplicationMutation<Input, Value>(
|
||||
.catch((error: unknown) => {
|
||||
const failure = withFailureEffect(
|
||||
normalizeUnknownFailure(error, {
|
||||
operationId: "APPLICATION_MUTATION",
|
||||
operationId: failureOperationId,
|
||||
}),
|
||||
"NOT_STARTED",
|
||||
);
|
||||
@@ -801,6 +809,7 @@ export function useApplicationMutation<Input, Value>(
|
||||
queryClient,
|
||||
definitionId,
|
||||
duplicatePolicy,
|
||||
failureOperationId,
|
||||
mutationIntentFactory,
|
||||
mutationOperationId,
|
||||
requiresIdempotencyKey,
|
||||
|
||||
Reference in New Issue
Block a user