Open ludovicfourrage opened 1 month ago
Does the issue also appear if use:enhance
is not used?
The prefix of the route with always ?/subscribe
likely resolves in ?/en/subscribe
, breaking the action. I would assume that use:enhance
has no effect on the issue.
Does the issue also appear if
use:enhance
is not used?The prefix of the route with always
?/subscribe
likely resolves in?/en/subscribe
, breaking the action. I would assume thatuse:enhance
has no effect on the issue.
No, the issue does not appear when removing use:enhance
I see use:enhance
interferes with routing under the hood. Ouch. I add this issue to the metaframework overhaul project https://github.com/opral/inlang-paraglide-js/issues/217
I see
use:enhance
interferes with routing under the hood. Ouch. I add this issue to the metaframework overhaul project #217
Yes but good news there seem to be a workaround by explicitly calling applyAction as per https://kit.svelte.dev/docs/form-actions#progressive-enhancement.
Change the form to
<form
method="POST"
action="?/subscribe"
use:enhance={handleEnhance}
>
and add the handleEnhanced function in the script:
const handleEnhance = ({ formElement, formData, action, cancel }: {
formElement: HTMLFormElement;
formData: FormData;
action: URL;
cancel: () => void;
}) => {
return async ({ result }: { result: ActionResult }) => {
// `result` is an `ActionResult` object
if (result.type === 'redirect') {
goto(result.location);
} else {
await applyAction(result);
}
};
};
This is only needed if the form is on the homepage by the way. Any other route seems to be working as expected without the workaround.
Using
Reproduction