跪拜 Guibai
← All articles
AI Programming · AIGC

Hands-On: AI Swaps Hand-Rolled Modals for Native <dialog> After Installing Four-Browser Skill Pack

By 小虎AI生活 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

AI coding assistants are trained on stale patterns, so they keep producing legacy front-end code even when modern APIs exist. This vendor-backed skill pack gives assistants a reference that changes the output: native <dialog>, focus management, and Esc handling become the default, reducing accessibility and maintenance bugs in generated code.

Summary

A six-prompt experiment against GoogleChrome/modern-web-guidance shows what happens when an AI coding assistant is given a curated textbook of modern web standards. Before the skill, the AI produced a water-reminder modal with a hand-built overlay div, inline onclick handlers, and manual Esc handling. After installing the skill, the same requirement used the native <dialog> element with a single showModal() call, cutting roughly thirty lines and gaining browser-managed focus, backdrop dimming, and Esc behavior. The tooltip case swapped coordinate-tracking code for CSS anchor positioning, narrowing 60-100 lines down to three declarations.

The test then applied the skill to a real single-file sign-in page. The built-in legacy scanner reported zero hits, because it only flags rules it is sure about. A manual review against the textbook, however, found nine modals built with hand-rolled masks, fifty-plus inline event handlers, thirty-plus innerHTML assignments, and no Esc handling at all. Rewriting one modal to use <dialog> moved the mask styles into ::backdrop and eliminated the boilerplate; open and close become one line.

The maintainability win is not simply a shorter file. It is that the AI is no longer responsible for remembering correctness details like focus return and Esc handling, which are easy to forget and hard to test when you write them by hand. The skill effectively takes behaviors the browser already provides and removes them from the developer's code.

Takeaways
— GoogleChrome/modern-web-guidance has over 18,000 stars and gained 1,000 in a day, maintained by Chrome, Edge, Firefox, and MDN.
— The skill pack contains over 200 modern web features and 200+ real-world patterns.
— In a before/after test, the same modal requirement dropped from a hand-built overlay with inline onclick to native <dialog> with one showModal() call, removing about 30 lines.
— The tooltip effect moved from coordinate calculation to CSS anchor positioning, reducing code from 60-100 lines to three declarations and two attributes, with no JS.
— A real sign-in page scan found 9 modal overlays, 50+ inline event handlers, 30+ innerHTML uses, and zero Esc handling.
— The built-in scanner reported zero legacy patterns because it only reports rules it is confident about; manual review against the textbook found many.
— The new approach gives browser-managed Esc, focus return, and backdrop animations without writing code.
Conclusions

The skill's conservative scanner that reports zero on a codebase with 50+ inline handlers shows why automated legacy detection is limited; the textbook-based manual comparison is what actually surfaces those patterns.

The maintainability argument is about removing hidden correctness obligations, not just counting lines; that's why the AI's shift to native APIs is a bigger deal than the code savings suggest.

Four browser vendors cooperating on this package is notable because AI assistants have historically learned from mixed, outdated training data; a shared, current reference is a new mechanism for steering their output.

Concepts & terms
modern-web-guidance
A skill pack maintained by Chrome, Edge, Firefox, and MDN, containing current web features and real-world patterns meant to be loaded by AI coding assistants before they generate code.
<dialog>
A native HTML element that provides a modal dialog with built-in focus trapping, Esc handling, and a backdrop, replacing hand-built overlay divs and custom JavaScript.
CSS anchor positioning
A CSS feature that positions an element relative to another element, letting the browser handle coordinate math and edge flipping, replacing manual JavaScript calculations for tooltips and popovers.
Agent Skill
A package of instructions, references, and examples that an AI assistant can install and load to steer its code generation toward specific practices, such as using modern web APIs.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗