Support HTTP methods beyond GET/POST in partial form submissions

Open Beginner friendly
#3,803 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
deno, typescript
Domain
frontend

Research direction

Start at the guard in packages/fresh/src/runtime/client/partials.ts around line 268, then check the fetch() call around line 309 and any nearby partial form tests. Confirm which methods should pass through and how the submission behavior is covered. Done means partial form submissions support the intended HTTP methods while GET and POST continue to work.

Written by the indexing model from the issue text.

Description

feat

Summary

Fresh's partial form handling currently only supports GET and POST methods. The guard at partials.ts:268 bails out for any other method:

if (lowerMethod !== "get" && lowerMethod !== "post") {
  return;
}

However, the code below (line 309) already passes method: lowerMethod to fetch(), so DELETE/PATCH/PUT would work if the guard were removed or expanded.

Motivation

Users want to use REST-style handlers with partials:

export const handler = define.handlers({
  POST(ctx) {
    return ctx.render(<Partial name="body">post!</Partial>);
  },
  DELETE(ctx) {
    return ctx.render(<Partial name="body">delete!</Partial>);
  },
  PATCH(ctx) {
    return ctx.render(<Partial name="body">patch!</Partial>);
  },
});

export default define.page(function Home() {
  return (
    <div f-client-nav>
      <Partial name="body">
        <form>
          <button type="submit" formmethod="POST">post</button>
          <button type="submit" formmethod="DELETE">delete</button>
          <button type="submit" formmethod="PATCH">patch</button>
        </form>
      </Partial>
    </div>
  );
});

Currently the workaround is creating a Form island that uses fetch() internally, which is janky.

Considerations

  • formmethod="DELETE" is not valid per the HTML spec — browsers without JS (or before the partial script loads) would treat unknown methods as GET. This is a progressive enhancement tradeoff.
  • One option is a Fresh-specific attribute (e.g. f-method="DELETE") to make it explicit that this only works with client nav enabled.
  • The minimal change is just removing/expanding the guard at line 268, since the fetch plumbing already handles arbitrary methods.

References

  • Discord discussion
  • Similar pattern popularized by htmx (hx-delete, hx-patch, etc.)
Dominant language
TypeScript
Stars
13.8k
Forks
757
Avg merge
3m
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from freshframework/fresh

All issues in freshframework/fresh

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.