Skip to content

DatasetteModal.alert() replaces native alert() calls - #3104

Merged
simonw merged 2 commits into
mainfrom
claude/agents-md-alert-f83bfe
Nov 22, 2026
Merged

simonw merged 2 commits into
mainfrom
claude/agents-md-alert-f83bfe

Conversation

@simonw

@simonw simonw commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Browsers embedded in other applications can dismiss a native alert() without showing it, so the user never sees the message. This adds an in-page replacement and uses it for the five alert() calls Datasette had left.

image
Claude Fable 5.2 High

The method

await DatasetteModal.alert({ message: "Could not save", okLabel: "OK" });

It takes an options object like DatasetteModal.confirm() and returns a promise that resolves when the user dismisses the dialog. alert() and confirm() now share one dialog-building helper in modal.js.

Accessibility compared with native alert()

Matching native behaviour:

  • It is a modal dialog with the alertdialog role, labelled by its message, so screen readers announce the message when it opens.
  • The rest of the page cannot be reached by keyboard or screen reader while it is open.
  • Focus moves to the button, so Enter, Space or Escape dismiss it.
  • Focus returns to the element that had it before.
  • Line breaks in the message are preserved.

Better than native:

  • A long message scrolls with the button still on screen.
  • It cannot be silently swallowed by an embedded browser.

One difference: it does not pause the calling script, so code that must run after dismissal has to await it. The documentation says so.

Changes

  • datasette/static/modal.js: new DatasetteModal.alert(), sharing a helper with confirm().
  • datasette/static/edit-tools-loader.js: the "Could not load the editing tools" message uses it.
  • datasette/templates/api_explorer.html: the four JSON and request errors use it.
  • datasette/static/app.css: the shared message style gains white-space: pre-wrap and scrolling. This also applies to confirm() dialogs.
  • docs/javascript_plugins.rst: new "Alert dialogs" section, plus a changelog entry.
  • AGENTS.md: the rule about native dialogs now names DatasetteModal.alert() as the fallback for errors with no better place in the page.

Testing

Four new Playwright tests cover the method itself, an alert on top of another dialog, the edit tools load failure, and the API explorer errors. The Chromium Playwright suite passes locally (184 tests). Firefox and WebKit were not run locally.

🤖 Generated with Claude Code

Browsers embedded in other applications can dismiss a native alert()
without showing it, so the message is never seen.

DatasetteModal.alert({message, okLabel}) shows the message in an
in-page alertdialog with a single button and returns a promise that
resolves when it is dismissed. It shares its implementation with
DatasetteModal.confirm().

The edit tools loader and the API explorer now use it in place of
alert(). Messages in both dialogs keep their line breaks and scroll
when too long to fit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (0c9c59f) to head (cfeff96).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3104   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         81      81           
  Lines      14574   14577    +3     
=====================================
- Misses     14574   14577    +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread docs/javascript_plugins.rst Outdated
Comment on lines +638 to +647
The dialog behaves like a native alert for keyboard and screen reader users:

- It is a modal dialog with the ``alertdialog`` role, labelled by its message, so screen readers announce the message when the dialog opens.
- The rest of the page cannot be reached with the keyboard or a screen reader while it is open.
- Keyboard focus moves to the button, so Enter, Space or Escape dismiss the dialog.
- Focus returns to the element that had it before the dialog opened.

A message that is too long to fit on the screen scrolls, with the button still visible.

An alert interrupts the user, so keep it for messages that have no better place. An error that relates to a form field or a dialog that is already open is better shown next to that field or inside that dialog.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Too much detail here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@simonw
simonw merged commit 1d629fb into main Nov 22, 2026
13 of 14 checks passed
@simonw
simonw deleted the claude/agents-md-alert-f83bfe branch November 22, 2026 05:54
@simonw simonw added this to the Datasette 1.0 stable milestone Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant