Skip to content

Support HTTP methods beyond GET/POST in partial form submissions #3803

@bartlomieju

Description

@bartlomieju

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions