Skip to content

Keep the open attribute the browser set on dialog and details - #981

Merged
schultek merged 9 commits into
schultek:mainfrom
BiAksoy:fix/keep-browser-set-open-attribute
Nov 18, 2026
Merged

schultek merged 9 commits into
schultek:mainfrom
BiAksoy:fix/keep-browser-set-open-attribute

Conversation

@BiAksoy

@BiAksoy BiAksoy commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #970.

On a rebuild, DomRenderElement.update removes every attribute the component didn't pass. For <dialog> and <details> that includes the open attribute the browser sets itself, through showModal(), show() or a click on <summary>. A dialog opened with showModal() then disappears but stays modal, so the page stays inert and close() no longer works.

open on dialog() and details() is now bool?, like checked on input:

  • not set: the renderer leaves the attribute alone, so the browser controls it
  • open: true or open: false: applied on every update

This is a breaking change. Code that left open out to keep the element closed now has to pass open: false, and open passed through attributes is no longer removed when it is left out. A server-rendered open that the client doesn't pass is kept on hydration.

Tests are in test/client/open_attribute_test.dart (browser) and test/server/html_test.dart.

Type of Change

  • ❌ Breaking change
  • 🛠️ Bug fix

Ready Checklist

  • I've read the Contribution Guide.
  • In case this PR changes one of the core packages, I've modified the respective CHANGELOG.md file using
    the semantic_changelog format.
  • I updated/added relevant documentation (doc comments with ///).
  • I added myself to the AUTHORS file (optional, if you want to).

@BiAksoy
BiAksoy requested a review from schultek as a code owner November 10, 2026 13:55
Copilot AI balanced review requested due to automatic review settings November 10, 2026 13:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Package Version Report

The following packages have been updated:
jaspr_test : 0.24.0-beta.1 -> 0.24.0-beta.2
jaspr_builder : 0.24.0-beta.1 -> 0.24.0-beta.2
jaspr : 0.24.0-beta.1 -> 0.24.0-beta.2
jaspr_cli : 0.24.0-beta.1 -> 0.24.0-beta.2

@schultek schultek left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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:

  1. In packages/jaspr/tool/data/html.json, add "explicit": true to the open attribute for dialog and details (and re-run code generation). This turns open into a nullable bool? open:

    • open: null (uncontrolled / omitted) -> omitted from the attributes map.
    • open: true -> 'open': 'true'
    • open: false -> 'open': 'false'
  2. In DomRenderElement.update:

    • Don't remove 'open' in attributesToRemove for dialog and details (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 (and continue so it doesn't set the literal string "false" on the DOM node).

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.

@BiAksoy

BiAksoy commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

I kept the flag because I didn't want to change what open means for existing code. Making it nullable is cleaner, so I'll switch to your version. I tried it locally and it handles everything from #970.

One thing to check with you: open passed through attributes, like details(attributes: {if (expanded) 'open': ''}), can't be closed by leaving it out any more, since the renderer no longer removes open on these two tags. Is that fine? The open parameter covers the case.

@schultek

Copy link
Copy Markdown
Owner

open passed through attributes can't be closed by leaving it out any more

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.
@BiAksoy

BiAksoy commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Switched to your version and updated the description. One side effect worth a look: a server-rendered open that the client doesn't pass is now kept on hydration.

@BiAksoy
BiAksoy requested a review from schultek November 12, 2026 15:29
@BiAksoy
BiAksoy requested a review from schultek November 12, 2026 19:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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

@BiAksoy

BiAksoy commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Merged main to resolve the CHANGELOG conflict from the 0.24.0-beta.1 release. The entry now sits in a new ## Unreleased 0.24.0-beta.2 section. Since your review on the 12th, the PR also sets open through the element's property as you asked, and calls close() when an open dialog gets open: false (the Copilot comment). Ready for another look.

schultek
schultek previously approved these changes Nov 17, 2026

@schultek schultek left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM

@schultek
schultek enabled auto-merge (squash) November 18, 2026 13:57
@schultek
schultek merged commit 36ea319 into schultek:main Nov 18, 2026
18 checks passed
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.

fix: A rebuild removes the open attribute that showModal() set, leaving a hidden modal dialog and an inert page

3 participants