Stop AI from writing outdated JS and use modern web native features
AI coding assistants often default to outdated div+JS patterns instead of modern browser native capabilities. By introducing modern web guidelines and best practices, you can significantly improve frontend code quality and reduce redundant implementations.
Hacker Newspaulirish
ChromeFirefoxEdgeMDNmodern-web-guidance
Added 2026-11-11 · originally published 2026-11-10
Key points
- Prioritize CSS.highlights for text range highlighting to avoid scattering span tags everywhere.
- Use native <dialog> and showModal() to handle backdrop dimming and proper focus management.
- Use field-sizing to make textareas automatically grow as the user types.
- Run legacy-scan on the source code to identify and modernize outdated legacy patterns.
Pitfalls
- AI does not proactively use platform native solutions by default and tends to rely on outdated div+JS patterns.
.cursorrules
- Prioritize browser native web primitives (such as native <dialog>, CSS.highlights, field-sizing) - Avoid outdated JS libraries or redundant DOM manipulations (such as inserting <span> everywhere or calculating heights with JS)
Copy-ready prompt
When writing frontend code, strictly use modern web native features and avoid legacy div+JS implementation patterns. For example: use native <dialog> and showModal() instead of custom modals, use field-sizing instead of JS auto-height adjustment, and use CSS.highlights for text highlighting. Functional modules involved: [enter specific frontend component or feature here]
#AI Frontend#Anti-Patterns#Modern Web#Refactoring
Related techniques
Summarized by AI from the original source - refer to the original post for details. Copyright belongs to the original author.