Skip to content

Commit e4adc3e

Browse files
committed
fix(prefs): rename default action -> savePrefs (SvelteKit named-action rule)
Vercel was returning 500 on every POST to /settings/notifications: Error: When using named actions, the default action cannot be used. PR #70 added a `resendVerification` named action while keeping the existing `default` action for the Save Changes form. SvelteKit forbids that combination — once any named action exists on a page, ALL forms must target a named action explicitly. The error was swallowed by use:enhance so the user just saw "nothing happens" on click; production logs surfaced it. Renames `default` -> `savePrefs` and points the Save Changes form at `?/savePrefs`. resendVerification is unchanged. Comment on the new action calls out the constraint so a future reviewer doesn't re-introduce a default.
1 parent 3be3764 commit e4adc3e

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/routes/(app)/settings/notifications/+page.server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ export const load: PageServerLoad = async ({ locals }) => {
3434
};
3535

3636
export const actions: Actions = {
37-
default: async ({ request, locals }) => {
37+
// SvelteKit rejects a `default` action when ANY named action is
38+
// also defined — the resendVerification action below makes this
39+
// page named-only, so the Save Changes form targets `?/savePrefs`
40+
// explicitly. Previously the default coexistence threw a 500 on
41+
// every POST. https://svelte.dev/docs/kit/form-actions#named-actions
42+
savePrefs: async ({ request, locals }) => {
3843
const formData = Object.fromEntries(await request.formData());
3944
const parsed = notificationSchema.safeParse(formData);
4045
if (!parsed.success) return fail(400, { errors: parsed.error.flatten().fieldErrors });

src/routes/(app)/settings/notifications/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
{/if}
145145

146146
<GlassCard>
147-
<form method="POST" use:enhance class="space-y-6">
147+
<form method="POST" action="?/savePrefs" use:enhance class="space-y-6">
148148
<fieldset class="m-0 border-0 p-0">
149149
<legend class="text-text-muted mb-3 text-xs font-medium tracking-wider uppercase">
150150
Overdue dose reminders

0 commit comments

Comments
 (0)