Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement form actions handlers #1286

Closed
wants to merge 7 commits into from

Conversation

Hebilicious
Copy link
Member

@Hebilicious Hebilicious commented Jun 6, 2023

πŸ”— Linked issue

nuxt/nuxt#20649
nuxt/nuxt#20852

https://github.com/Hebilicious/form-actions-nuxt

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds an experimental features that allows Nitro to supports fallback routes.

This is useful to register a post handler alongside the nuxt renderer.
nitro.config.handlers.push({ route: "/hello-world", handler: "~/actions/hello-world.ts", formAction: true })

Nitro will send an error if there's a form action handler but no renderer has been specified.

When hitting /hello-world with a post request, the registered handler will be used.
But when hitting /hello-world with a get request, the renderer will be used.

Something to potentially do in the future would be to add the action directory to the nitro scanners.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Merging #1286 (96d261f) into main (1950d1e) will increase coverage by 0.09%.
The diff coverage is n/a.

❗ Current head 96d261f differs from pull request most recent head dabd367. Consider uploading reports for the commit dabd367 to get more accurate results

@@            Coverage Diff             @@
##             main    #1286      +/-   ##
==========================================
+ Coverage   76.73%   76.83%   +0.09%     
==========================================
  Files          71       68       -3     
  Lines        7273     6829     -444     
  Branches      727      692      -35     
==========================================
- Hits         5581     5247     -334     
+ Misses       1691     1580     -111     
- Partials        1        2       +1     

see 24 files with indirect coverage changes

@Hebilicious
Copy link
Member Author

Hebilicious commented Jun 18, 2023

@pi0 This is ready for review, I followed the approach that you suggested with a separated router for form actions

@pi0
Copy link
Member

pi0 commented Aug 6, 2023

With the upstream fix in h3 (unjs/h3#461), we can actually register form action routes with their method and no additional configuration and they are expected to work nicely with the default renderer catch-all route.

@Hebilicious
Copy link
Member Author

Hebilicious commented Aug 8, 2023

Thanks @pi0, I can confirm that everything is working smoothly.
I've upgraded https://github.com/Hebilicious/form-actions-nuxt/releases/tag/v0.2.0-beta.0 to use the latest nitro and h3 πŸŽ‰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants