Skip to content

Polyfill remote-dom FormData using the native Worker implementation#621

Open
developit wants to merge 3 commits into
mainfrom
cx-formdata-worker-polyfill
Open

Polyfill remote-dom FormData using the native Worker implementation#621
developit wants to merge 3 commits into
mainfrom
cx-formdata-worker-polyfill

Conversation

@developit

Copy link
Copy Markdown
Contributor

Summary

Bridge remote-dom forms to the native FormData implementation available in Web Workers, instead of reimplementing the API. This keeps the polyfill small while preserving native behavior for storage, iteration, file handling, and multipart request interoperability.

What changed

  • Capture the environment’s native FormData constructor and use it to build form data from remote-dom controls.
  • Populate FormData from the common subset of successful controls supported by remote-dom.
  • Detect checkable controls by property presence so custom elements participate correctly.
  • Avoid triggering unrelated property reads when controls are omitted from submission.

Notes

  • The implementation intentionally stays minimal and leans on the browser’s native FormData semantics.
  • Custom checked controls are supported via property-based detection rather than input type heuristics.

Capture the environment native constructor and populate it from the common
subset of successful Remote DOM controls. This keeps native storage, file
handling, iteration, and multipart Request interoperability intact.
Avoid inferring checkable behavior from input type names so Remote DOM custom
elements participate correctly. Cover custom checked properties and document
the property-based behavior.
Use explicit early continues so omitted controls do not trigger unrelated
property reads. Keep each omission rule independent and let downstream
minification combine conditions when useful.
continue;
}

data.append(name, control.value ?? control.getAttribute('value') ?? '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked elements submit "on" as a fallback if the value attribute isn't there

Otherwise, if the field element is an input element whose type attribute is in the Checkbox state or the Radio Button state:

If the field element has a value attribute specified, then let value be the value of that attribute; otherwise, let value be the string "on".

step 7.1 here https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants