npx skills add https://github.com/pbakaus/impeccable --skill harden强化接口以应对边界情况、错误、国际化问题以及破坏理想化设计的真实使用场景。
识别弱点和边界情况:
* 超长文本(名称、描述、标题)
* 超短文本(空、单个字符)
* 特殊字符(表情符号、RTL 文本、重音符号)
* 大数字(百万、十亿)
* 大量项目(1000+ 列表项、50+ 选项)
* 无数据(空状态)
2. 测试错误场景:
* 网络故障(离线、缓慢、超时)
* API 错误(400、401、403、404、500)
* 验证错误
* 权限错误
* 速率限制
* 并发操作
3. 测试国际化:
* 长翻译(德语通常比英语长 30%)
* RTL 语言(阿拉伯语、希伯来语)
* 字符集(中文、日文、韩文、表情符号)
* 日期/时间格式
* 数字格式(1,000 对比 1.000)
* 货币符号
关键:仅适用于完美数据的设计不具备生产就绪性。需针对现实情况进行强化。
系统性地提高韧性:
长文本处理:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
/* Single line with ellipsis */
.truncate {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* Multi-line with clamp */
.line-clamp {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
/* Allow wrapping */
.wrap {
word-wrap: break-word;
overflow-wrap: break-word;
hyphens: auto;
}
Flex/Grid 溢出:
/* Prevent flex items from overflowing */
.flex-item {
min-width: 0; /* Allow shrinking below content size */
overflow: hidden;
}
/* Prevent grid items from overflowing */
.grid-item {
min-width: 0;
min-height: 0;
}
响应式文本大小调整:
clamp() 实现流体排版文本扩展:
// ❌ Bad: Assumes short English text
<button className="w-24">Submit</button>
// ✅ Good: Adapts to content
<button className="px-4 py-2">Submit</button>
RTL(从右到左)支持:
/* Use logical properties */
margin-inline-start: 1rem; /* Not margin-left */
padding-inline: 1rem; /* Not padding-left/right */
border-inline-end: 1px solid; /* Not border-right */
/* Or use dir attribute */
[dir="rtl"] .arrow { transform: scaleX(-1); }
字符集支持:
日期/时间格式化:
// ✅ Use Intl API for proper formatting
new Intl.DateTimeFormat('en-US').format(date); // 1/15/2024
new Intl.DateTimeFormat('de-DE').format(date); // 15.1.2024
new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD'
}).format(1234.56); // $1,234.56
复数形式:
// ❌ Bad: Assumes English pluralization
`${count} item${count !== 1 ? 's' : ''}`
// ✅ Good: Use proper i18n library
t('items', { count }) // Handles complex plural rules
网络错误:
// Error states with recovery
{error && (
<ErrorMessage>
<p>Failed to load data. {error.message}</p>
<button onClick={retry}>Try again</button>
</ErrorMessage>
)}
表单验证错误:
API 错误:
优雅降级:
空状态:
加载状态:
大型数据集:
并发操作:
权限状态:
浏览器兼容性:
客户端验证:
服务端验证(必须):
约束处理:
<!-- Set clear constraints -->
<input
type="text"
maxlength="100"
pattern="[A-Za-z0-9]+"
required
aria-describedby="username-hint"
/>
<small id="username-hint">
Letters and numbers only, up to 100 characters
</small>
键盘导航:
屏幕阅读器支持:
运动敏感性:
@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
高对比度模式:
慢速连接:
内存泄漏:
节流与防抖:
// Debounce search input
const debouncedSearch = debounce(handleSearch, 300);
// Throttle scroll handler
const throttledScroll = throttle(handleScroll, 100);
手动测试:
自动化测试:
重要:强化就是预料到意料之外的情况。真实用户会做出你从未想象过的事情。
切勿:
使用边界情况彻底测试:
请记住:您是为生产现实进行强化,而不是为了演示的完美。预期用户会输入奇怪的数据、在流程中断开连接,并以意想不到的方式使用您的产品。将韧性构建到每个组件中。
每周安装量
27.7K
代码仓库
GitHub 星标
13.4K
首次出现
Mar 4, 2026
安全审计
安装于
codex27.0K
opencode26.9K
github-copilot26.9K
gemini-cli26.8K
cursor26.8K
amp26.8K
Strengthen interfaces against edge cases, errors, internationalization issues, and real-world usage scenarios that break idealized designs.
Identify weaknesses and edge cases:
Test with extreme inputs :
Test error scenarios :
Test internationalization :
CRITICAL : Designs that only work with perfect data aren't production-ready. Harden against reality.
Systematically improve resilience:
Long text handling :
/* Single line with ellipsis */
.truncate {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* Multi-line with clamp */
.line-clamp {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
/* Allow wrapping */
.wrap {
word-wrap: break-word;
overflow-wrap: break-word;
hyphens: auto;
}
Flex/Grid overflow :
/* Prevent flex items from overflowing */
.flex-item {
min-width: 0; /* Allow shrinking below content size */
overflow: hidden;
}
/* Prevent grid items from overflowing */
.grid-item {
min-width: 0;
min-height: 0;
}
Responsive text sizing :
clamp() for fluid typographyText expansion :
Add 30-40% space budget for translations
Use flexbox/grid that adapts to content
Test with longest language (usually German)
Avoid fixed widths on text containers
// ❌ Bad: Assumes short English text <button className="w-24">Submit</button>
// ✅ Good: Adapts to content <button className="px-4 py-2">Submit</button>
RTL (Right-to-Left) support :
/* Use logical properties */
margin-inline-start: 1rem; /* Not margin-left */
padding-inline: 1rem; /* Not padding-left/right */
border-inline-end: 1px solid; /* Not border-right */
/* Or use dir attribute */
[dir="rtl"] .arrow { transform: scaleX(-1); }
Character set support :
Date/Time formatting :
// ✅ Use Intl API for proper formatting
new Intl.DateTimeFormat('en-US').format(date); // 1/15/2024
new Intl.DateTimeFormat('de-DE').format(date); // 15.1.2024
new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD'
}).format(1234.56); // $1,234.56
Pluralization :
// ❌ Bad: Assumes English pluralization
`${count} item${count !== 1 ? 's' : ''}`
// ✅ Good: Use proper i18n library
t('items', { count }) // Handles complex plural rules
Network errors :
Show clear error messages
Provide retry button
Explain what happened
Offer offline mode (if applicable)
Handle timeout scenarios
// Error states with recovery {error && ( <ErrorMessage> <p>Failed to load data. {error.message}</p> <button onClick={retry}>Try again</button> </ErrorMessage> )}
Form validation errors :
API errors :
Graceful degradation :
Empty states :
Loading states :
Large datasets :
Concurrent operations :
Permission states :
Browser compatibility :
Client-side validation :
Server-side validation (always):
Constraint handling :
<!-- Set clear constraints -->
<input
type="text"
maxlength="100"
pattern="[A-Za-z0-9]+"
required
aria-describedby="username-hint"
/>
<small id="username-hint">
Letters and numbers only, up to 100 characters
</small>
Keyboard navigation :
Screen reader support :
Motion sensitivity :
@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
High contrast mode :
Slow connections :
Memory leaks :
Throttling & Debouncing:
// Debounce search input
const debouncedSearch = debounce(handleSearch, 300);
// Throttle scroll handler
const throttledScroll = throttle(handleScroll, 100);
Manual testing :
Automated testing :
IMPORTANT : Hardening is about expecting the unexpected. Real users will do things you never imagined.
NEVER :
Test thoroughly with edge cases:
Remember: You're hardening for production reality, not demo perfection. Expect users to input weird data, lose connection mid-flow, and use your product in unexpected ways. Build resilience into every component.
Weekly Installs
27.7K
Repository
GitHub Stars
13.4K
First Seen
Mar 4, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex27.0K
opencode26.9K
github-copilot26.9K
gemini-cli26.8K
cursor26.8K
amp26.8K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装