You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a Button with form attribute is unmounted / detached, an unhandled exception is thrown (see details below).
Use case: I have a Button component that is outside of the form, so it has a form attribute. When I click the button, my code does some work, and then renders a different page, so the submit button is eventually unmounted (detached) from the DOM. The form itself may or may not remain mounted.
Note that the demo has a setTimeout delay to be more realistic (async submit), but it throws without setTimeout just as well.
Note that the element in the doc variable mentioned below may or may not contain the form. It depends on which element(s) in the tree are getting unmounted, so merely replacing getElementById with querySelector will not solve the issue.
When button is unmounted, internally this snippet from button.component.ts is run:
It seems that because input is already unmounted (detached from the DOM) when this is run, and input itself not inside shadow DOM, input.getRootNode() returns its parent element / detached root (<div id="actionButtons">), not the document, as per MDN. However, the code assumes that doc is a document, and fails when the regular element does not have a getElementById method.
I don't know enough about Shoelace to say if this is an individual edge case, or a general problem that could happen with other form components too.
The text was updated successfully, but these errors were encountered:
raquo
added
the
bug
Things that aren't working right in the library.
label
Jan 8, 2024
cyantree
added a commit
to cyantree/shoelace
that referenced
this issue
Feb 20, 2024
Describe the bug
When a Button with
form
attribute is unmounted / detached, an unhandled exception is thrown (see details below).Use case: I have a Button component that is outside of the form, so it has a
form
attribute. When I click the button, my code does some work, and then renders a different page, so the submit button is eventually unmounted (detached) from the DOM. The form itself may or may not remain mounted.To Reproduce
Steps to reproduce the behavior:
Screenshots
Browser / OS
Additional information
Note that the demo has a setTimeout delay to be more realistic (async submit), but it throws without setTimeout just as well.
Note that the element in the
doc
variable mentioned below may or may not contain theform
. It depends on which element(s) in the tree are getting unmounted, so merely replacinggetElementById
withquerySelector
will not solve the issue.When button is unmounted, internally this snippet from
button.component.ts
is run:It seems that because
input
is already unmounted (detached from the DOM) when this is run, andinput
itself not inside shadow DOM,input.getRootNode()
returns its parent element / detached root (<div id="actionButtons">
), not the document, as per MDN. However, the code assumes thatdoc
is a document, and fails when the regular element does not have agetElementById
method.I don't know enough about Shoelace to say if this is an individual edge case, or a general problem that could happen with other form components too.
The text was updated successfully, but these errors were encountered: