Add a way to intercept and change form action result in handle hook
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the problem
There's no native way to intercept form actions and changing its result before being rendered.
Why I need this
I'm experimenting automatic endpoint/form validation based on the defined schema file. I will load all needed schemas in the hook handle and validate them and return result back to user. Something similar to what's in Fastify framework
For standalone endpoints this works fine. but with form actions, this is challenging as I have to render the page with the error props but sveltekit yet doesn't provide any mechanism to change that.
Describe the proposed solution
We could either have a seperate hook function in hooks.server or provide a callback in resolve function similar to transformPageChunk
Alternatives considered
- Manually define the desired behavior in each form action with a shared function. but this is redundant
- A hacky way to use transformPageChunk to replace form in
kit.start(app, __sveltekit_dev.element, { node_ids: [0, 2], data, form: null, error: null });with the desired results. but this is a hacky solution and requires more testing and could break pages and introduce security issues.
Importance
would make my life easier
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the hooks.server and resolve entry points, then compare the proposed callback with the existing transformPageChunk behavior and the form handling in kit.start. The work is complete when the project has a supported way to intercept and change form action results before they are rendered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100