Skip to content

FOLLOW-UP: Type sendHTTPMultipart payload to enforce FormData pre-capture contract (from PR #58) #66

@adnaan

Description

@adnaan

Context

This follow-up task was identified during the review of PR #58.

Source PR: #58
PR Title: fix: cross-handler SPA navigation, navigation edge cases, and Tier 1 file uploads
Suggested by: @claude[bot]
Priority: Low

Task Description

LiveTemplateClient.sendHTTPMultipart(form, action, formData) has several caller responsibilities that are currently enforced only by doc comments:

  1. FormData must be built BEFORE setActiveSubmission disables the fieldset (otherwise it's empty)
  2. FormData must already include the lvt-action entry
  3. Callers must not mutate or reuse the passed FormData after the call

These implementation details leak into the public method signature. Since the only real caller is EventDelegator (via EventDelegationContext.sendHTTPMultipart), the contract is contained in practice — but a dedicated payload type could enforce it statically.

Proposed Fix

Introduce a branded type or interface that encodes the contract:

// Example shape — actual design TBD
interface Tier1UploadPayload {
  readonly form: HTMLFormElement;
  readonly action: string;
  readonly formData: FormData; // pre-captured, includes lvt-action
}

sendTier1Upload(payload: Tier1UploadPayload): void;

The EventDelegator would be the only factory for Tier1UploadPayload, ensuring the contract is met at construction time.

Original Comment

The method is public and the doc comment lists requirements callers must meet: build FormData before fieldset disable, include lvt-action, don't mutate. Since the only real caller is EventDelegator via EventDelegationContext, this is contained — but these feel like internal implementation details leaking into the interface. Consider whether a dedicated payload type could enforce the contract at compile time rather than via doc comment.


This issue was created from PR #58 review comments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfollow-upFollow-up task from PR reviewfrom-reviewIssue originated from PR review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions