Describe the bug and the expected behavior
This is obviously quite a niche scenario, but I've noticed that Conform does not work correctly when a form is used either within an iframe or within the shadow dom.
Expected behaviours:
- when used within either an iframe or the shadow dom
form.update programmatically sets target field values
- using a submit button submits the form
Current behaviours:
- when used within either an iframe or the shadow dom
form.update throws an uncaught error of Uncaught Error: Failed to submit the form. The element provided is null or undefined.
- using a submit button throws an uncaught error of
The submit event is dispatched by form#«r1» instead of form#«r1»
Conform version
v1.4
Steps to Reproduce the Bug or Issue
- Use Conform to handle a form within either an iframe or within the shadow dom
- Attempt to use either
form.update or a basic submit
Recreated in sandbox: https://codesandbox.io/p/sandbox/react-typescript-forked-hn7hxl
(Open the sandbox terminal to see further error details)
What browsers are you seeing the problem on?
No response
Screenshots or Videos
No response
Additional context
Looking through the Conform repo, I believe this issue is likely down to the use of the global document
e.g.
function getFormElement(): HTMLFormElement | null {
return document.forms.namedItem(latestOptions.formId);
}
the parent window's document does not have access to a form element, should it exist within either a child iframe or the shadow dom.
Possible (?) option:
Rather than use document.forms, perhaps a react Ref could be used to keep a reference of the form element. If needed, the owning document could then be reached via .ownerDocument on that form element.
Describe the bug and the expected behavior
This is obviously quite a niche scenario, but I've noticed that Conform does not work correctly when a form is used either within an iframe or within the shadow dom.
Expected behaviours:
form.updateprogrammatically sets target field valuesCurrent behaviours:
form.updatethrows an uncaught error ofUncaught Error: Failed to submit the form. The element provided is null or undefined.The submit event is dispatched by form#«r1» instead of form#«r1»Conform version
v1.4
Steps to Reproduce the Bug or Issue
form.updateor a basic submitRecreated in sandbox: https://codesandbox.io/p/sandbox/react-typescript-forked-hn7hxl
(Open the sandbox terminal to see further error details)
What browsers are you seeing the problem on?
No response
Screenshots or Videos
No response
Additional context
Looking through the Conform repo, I believe this issue is likely down to the use of the global
documente.g.
the parent window's document does not have access to a form element, should it exist within either a child iframe or the shadow dom.
Possible (?) option:
Rather than use
document.forms, perhaps a react Ref could be used to keep a reference of the form element. If needed, the owning document could then be reached via.ownerDocumenton that form element.