Repository navigation
Keep the open attribute the browser set on dialog and details - #981
Conversation
Package Version ReportThe following packages have been updated: |
schultek
left a comment
There was a problem hiding this comment.
Thanks for the PR and the great writeup and test coverage!
I was looking at this and thinking about why we need to track _renderedOpen across updates in the first place. Right now, dialog() and dialog(open: false) are indistinguishable because both omit the 'open' attribute from the attributes map, which forces us to remember the previous render state.
We actually have a pattern for this exact scenario with checked and indeterminate on input. We can make open an explicitBool:
-
In
packages/jaspr/tool/data/html.json, add"explicit": trueto theopenattribute fordialoganddetails(and re-run code generation). This turnsopeninto a nullablebool? open:open: null(uncontrolled / omitted) -> omitted from the attributes map.open: true->'open': 'true'open: false->'open': 'false'
-
In
DomRenderElement.update:- Don't remove
'open'inattributesToRemovefordialoganddetails(so uncontrolled elements aren't touched on rebuilds). - In the attribute update loop, handle
'open'when it is present: if'true', ensure the attribute is set; if'false', remove it (andcontinueso it doesn't set the literal string"false"on the DOM node).
- Don't remove
This way DomRenderElement stays completely stateless (no need for _hasOpenState or _renderedOpen), while cleanly supporting both controlled (open: true / open: false) and uncontrolled (dialog() / details()) usage with showModal(), close(), and <summary> clicks.
|
Thanks for the review! I kept the flag because I didn't want to change what One thing to check with you: |
I think thats fine. With this PR we change the semantics to "if the attribute is not provided, let the browser take control of the open state" instead of "not provided means closed". Which is a breaking change, but I think a reasonable new semantic. |
Replaces the flag in DomRenderElement, as suggested in review. When open is not passed the renderer leaves the attribute to the browser, and open: true or open: false is applied on every update, like checked on input.
|
Switched to your version and updated the description. One side effect worth a look: a server-rendered |
There was a problem hiding this comment.
🟡 Changes recommended
Setting .open = false on a dialog opened with showModal() bypasses closing steps, leaving the page inert and unrecoverable via close(); use close() for this transition and add a browser regression test.
1 open issue
Review effort: Balanced
…t-open-attribute # Conflicts: # packages/jaspr/CHANGELOG.md
|
Merged |

Description
Fixes #970.
On a rebuild,
DomRenderElement.updateremoves every attribute the component didn't pass. For<dialog>and<details>that includes theopenattribute the browser sets itself, throughshowModal(),show()or a click on<summary>. A dialog opened withshowModal()then disappears but stays modal, so the page stays inert andclose()no longer works.openondialog()anddetails()is nowbool?, likecheckedoninput:open: trueoropen: false: applied on every updateThis is a breaking change. Code that left
openout to keep the element closed now has to passopen: false, andopenpassed throughattributesis no longer removed when it is left out. A server-renderedopenthat the client doesn't pass is kept on hydration.Tests are in
test/client/open_attribute_test.dart(browser) andtest/server/html_test.dart.Type of Change
Ready Checklist
the semantic_changelog format.
///).