fix(notifications): move onClose/goto into enhance result callback

onClose() and goto() were firing before the server responded, making it
impossible for a fail() response to cancel navigation. Moved them inside
the result callback behind a result.type !== 'failure' guard.

Updated the $app/forms enhance mock to always invoke the returned async
callback with a configurable mockFormResult, and added three tests:
- success path calls onClose + goto with the correct deep-link URL
- failure path skips onClose and goto
- annotationId is appended to the URL when present

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-19 23:54:15 +02:00
parent af84ffc379
commit f9340366d1
2 changed files with 97 additions and 14 deletions

View File

@@ -84,15 +84,17 @@ function handleViewAll() {
class="contents"
use:enhance={() => {
optimisticMarkRead(notification.id);
onClose();
goto(
buildCommentHref(
notification.documentId,
notification.referenceId,
notification.annotationId
)
);
return async ({ update }) => {
return async ({ result, update }) => {
if (result.type !== 'failure') {
onClose();
goto(
buildCommentHref(
notification.documentId,
notification.referenceId,
notification.annotationId
)
);
}
await update({ reset: false, invalidateAll: false });
};
}}