Skip to content

Commit a885d35

Browse files
committed
Fixed flash messages being displayed early.
1 parent b65f8e5 commit a885d35

File tree

5 files changed

+37
-39
lines changed

5 files changed

+37
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ Headlines: Added, Changed, Deprecated, Removed, Fixed, Security
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [1.0.0-rc.4]
99

1010
### Changed
1111

12-
- It's not possible to send arbitrary data to `superForm` anymore, a `SuperValidated` structure is required, which is retured from `superValidate`, so in most cases this is not a problem.
12+
- It's not possible to send arbitrary data to `superForm` anymore, a `SuperValidated` structure is required, which is returned from `superValidate` on the server and `superValidateSync`, so in most cases this is not a problem.
1313
- Reverted that `message/setMessage` and `setError` will throw an error if status is lower than 400. Using a range error type check instead.
1414

1515
### Fixed
1616

17+
- Fixed flash messages being displayed early. This update also means that at least [sveltekit-flash-message](https://github.com/ciscoheat/sveltekit-flash-message) 1.0.0-rc.3 is required to work together with Superforms.
1718
- Form data was reset to its previous state when `error` was thrown.
1819
- Form-level errors can be added with `setError`, using an empty string as path.
1920

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@
103103
"prettier": "^2.8.8",
104104
"prettier-plugin-svelte": "^2.10.1",
105105
"publint": "^0.1.12",
106-
"sass": "^1.62.1",
106+
"sass": "^1.63.2",
107107
"slugify": "^1.6.6",
108108
"svelte": "^3.59.1",
109109
"svelte-check": "^3.4.3",
110-
"sveltekit-flash-message": "1.0.0-rc.2",
110+
"sveltekit-flash-message": "1.0.0-rc.3",
111111
"sveltekit-rate-limiter": "^0.1.8",
112112
"throttle-debounce": "^5.0.0",
113113
"tslib": "^2.5.3",

pnpm-lock.yaml

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/client/formEnhance.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,16 +535,13 @@ export function formEnhance<T extends AnyZodObject, M>(
535535
}
536536
}
537537

538-
// Set flash message, which should be set in all cases, even
539-
// if we have redirected (which is the point of the flash message!)
538+
// Trigger flash message event if there was an error
540539
if (options.flashMessage) {
541540
if (result.type == 'error' && options.flashMessage.onError) {
542541
await options.flashMessage.onError({
543542
result,
544543
message: options.flashMessage.module.getFlash(page)
545544
});
546-
} else if (result.type != 'error') {
547-
await options.flashMessage.module.updateFlash(page);
548545
}
549546
}
550547
}

src/lib/client/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export type FormOptions<T extends ZodValidation<AnyZodObject>, M> = Partial<{
130130
updateFlash(
131131
page: Readable<Page>,
132132
update?: () => Promise<void>
133-
): Promise<void>;
133+
): Promise<boolean>;
134134
};
135135
onError?: (event: {
136136
result: {
@@ -782,7 +782,7 @@ export function superForm<
782782

783783
if (pageUpdate.form && typeof pageUpdate.form === 'object') {
784784
// Check if it is an error result, sent here from formEnhance
785-
if(pageUpdate.form.type == 'error') return
785+
if (pageUpdate.form.type == 'error') return;
786786

787787
const forms = Context_findValidationForms(pageUpdate.form);
788788
if (!forms.length) error('$page.form (ActionData)');

0 commit comments

Comments
 (0)