harden
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStrengthen interfaces against edge cases, errors, internationalization issues, and real-world usage scenarios that break idealized designs.
增强界面应对边缘场景、错误、国际化问题以及那些会打破理想化设计的真实使用场景的能力。
Assess Hardening Needs
评估界面强化需求
Identify weaknesses and edge cases:
-
Test with extreme inputs:
- Very long text (names, descriptions, titles)
- Very short text (empty, single character)
- Special characters (emoji, RTL text, accents)
- Large numbers (millions, billions)
- Many items (1000+ list items, 50+ options)
- No data (empty states)
-
Test error scenarios:
- Network failures (offline, slow, timeout)
- API errors (400, 401, 403, 404, 500)
- Validation errors
- Permission errors
- Rate limiting
- Concurrent operations
-
Test internationalization:
- Long translations (German is often 30% longer than English)
- RTL languages (Arabic, Hebrew)
- Character sets (Chinese, Japanese, Korean, emoji)
- Date/time formats
- Number formats (1,000 vs 1.000)
- Currency symbols
CRITICAL: Designs that only work with perfect data aren't production-ready. Harden against reality.
识别薄弱点与边缘场景:
-
使用极端输入测试:
- 极长文本(名称、描述、标题)
- 极短文本(空内容、单个字符)
- 特殊字符(表情符号、RTL文本、带重音的字符)
- 大数字(百万、十亿级)
- 大量条目(1000+列表项、50+选项)
- 无数据(空状态)
-
测试错误场景:
- 网络故障(离线、慢速、超时)
- API错误(400、401、403、404、500)
- 验证错误
- 权限错误
- 请求频率限制
- 并发操作
-
测试国际化支持:
- 长翻译文本(德语通常比英语长30%)
- 从右到左(RTL)语言(阿拉伯语、希伯来语)
- 字符集(中文、日文、韩文、表情符号)
- 日期/时间格式
- 数字格式(1,000 vs 1.000)
- 货币符号
关键提示:仅能处理完美数据的设计不具备生产环境可用性。要针对真实场景强化界面。
Hardening Dimensions
界面强化维度
Systematically improve resilience:
系统性提升界面韧性:
Text Overflow & Wrapping
文本溢出与换行处理
Long text handling:
css
/* 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:
css
/* 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:
- Use for fluid typography
clamp() - Set minimum readable sizes (14px on mobile)
- Test text scaling (zoom to 200%)
- Ensure containers expand with text
长文本处理:
css
/* 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 溢出处理:
css
/* 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() - 设置最小可读尺寸(移动端14px)
- 测试文本缩放(放大至200%)
- 确保容器随文本内容扩展
Internationalization (i18n)
国际化(i18n)
Text 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
jsx
// ❌ 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:
css
/* 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:
- Use UTF-8 encoding everywhere
- Test with Chinese/Japanese/Korean (CJK) characters
- Test with emoji (they can be 2-4 bytes)
- Handle different scripts (Latin, Cyrillic, Arabic, etc.)
Date/Time formatting:
javascript
// ✅ 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.56Pluralization:
javascript
// ❌ Bad: Assumes English pluralization
`${count} item${count !== 1 ? 's' : ''}`
// ✅ Good: Use proper i18n library
t('items', { count }) // Handles complex plural rules文本扩展适配:
- 为翻译文本预留30-40%的空间
- 使用可自适应内容的flexbox/grid布局
- 用最长语言(通常是德语)测试
- 避免为文本容器设置固定宽度
jsx
// ❌ Bad: Assumes short English text
<button className="w-24">Submit</button>
// ✅ Good: Adapts to content
<button className="px-4 py-2">Submit</button>RTL(从右到左)支持:
css
/* 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); }字符集支持:
- 全链路使用UTF-8编码
- 测试中文/日文/韩文(CJK)字符
- 测试表情符号(可能占2-4字节)
- 适配不同书写体系(拉丁语、西里尔语、阿拉伯语等)
日期/时间格式化:
javascript
// ✅ 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复数处理:
javascript
// ❌ Bad: Assumes English pluralization
`${count} item${count !== 1 ? 's' : ''}`
// ✅ Good: Use proper i18n library
t('items', { count }) // Handles complex plural rulesError Handling
错误处理
Network errors:
- Show clear error messages
- Provide retry button
- Explain what happened
- Offer offline mode (if applicable)
- Handle timeout scenarios
jsx
// Error states with recovery
{error && (
<ErrorMessage>
<p>Failed to load data. {error.message}</p>
<button onClick={retry}>Try again</button>
</ErrorMessage>
)}Form validation errors:
- Inline errors near fields
- Clear, specific messages
- Suggest corrections
- Don't block submission unnecessarily
- Preserve user input on error
API errors:
- Handle each status code appropriately
- 400: Show validation errors
- 401: Redirect to login
- 403: Show permission error
- 404: Show not found state
- 429: Show rate limit message
- 500: Show generic error, offer support
Graceful degradation:
- Core functionality works without JavaScript
- Images have alt text
- Progressive enhancement
- Fallbacks for unsupported features
网络错误:
- 显示清晰的错误提示
- 提供重试按钮
- 解释错误原因
- (如适用)提供离线模式
- 处理超时场景
jsx
// Error states with recovery
{error && (
<ErrorMessage>
<p>Failed to load data. {error.message}</p>
<button onClick={retry}>Try again</button>
</ErrorMessage>
)}表单验证错误:
- 在输入字段附近显示内联错误
- 清晰、具体的错误提示
- 提供修正建议
- 避免不必要地阻止提交
- 错误发生时保留用户输入内容
API错误:
- 针对不同状态码进行恰当处理
- 400:显示验证错误
- 401:重定向至登录页
- 403:显示权限错误
- 404:显示未找到状态
- 429:显示请求频率限制提示
- 500:显示通用错误,提供支持入口
优雅降级:
- 核心功能在无JavaScript环境下可正常使用
- 图片添加alt文本
- 渐进式增强
- 为不支持的功能提供降级方案
Edge Cases & Boundary Conditions
边缘场景与边界条件
Empty states:
- No items in list
- No search results
- No notifications
- No data to display
- Provide clear next action
Loading states:
- Initial load
- Pagination load
- Refresh
- Show what's loading ("Loading your projects...")
- Time estimates for long operations
Large datasets:
- Pagination or virtual scrolling
- Search/filter capabilities
- Performance optimization
- Don't load all 10,000 items at once
Concurrent operations:
- Prevent double-submission (disable button while loading)
- Handle race conditions
- Optimistic updates with rollback
- Conflict resolution
Permission states:
- No permission to view
- No permission to edit
- Read-only mode
- Clear explanation of why
Browser compatibility:
- Polyfills for modern features
- Fallbacks for unsupported CSS
- Feature detection (not browser detection)
- Test in target browsers
空状态:
- 列表无条目
- 无搜索结果
- 无通知
- 无数据可展示
- 提供清晰的下一步操作指引
加载状态:
- 初始加载
- 分页加载
- 刷新操作
- 明确显示正在加载的内容(如“加载你的项目中...”)
- 为长耗时操作提供时间预估
大型数据集:
- 分页或虚拟滚动
- 搜索/筛选功能
- 性能优化
- 避免一次性加载全部10000条数据
并发操作:
- 防止重复提交(加载时禁用按钮)
- 处理竞态条件
- 带回滚机制的乐观更新
- 冲突解决
权限状态:
- 无查看权限
- 无编辑权限
- 只读模式
- 清晰解释原因
浏览器兼容性:
- 为现代特性提供Polyfill
- 为不支持的CSS提供降级方案
- 特性检测(而非浏览器检测)
- 在目标浏览器中测试
Input Validation & Sanitization
输入验证与清理
Client-side validation:
- Required fields
- Format validation (email, phone, URL)
- Length limits
- Pattern matching
- Custom validation rules
Server-side validation (always):
- Never trust client-side only
- Validate and sanitize all inputs
- Protect against injection attacks
- Rate limiting
Constraint handling:
html
<!-- 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>客户端验证:
- 必填字段校验
- 格式验证(邮箱、电话、URL)
- 长度限制
- 模式匹配
- 自定义验证规则
服务端验证(必须做):
- 绝不只依赖客户端验证
- 验证并清理所有输入
- 防范注入攻击
- 请求频率限制
约束处理:
html
<!-- 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>Accessibility Resilience
无障碍访问韧性
Keyboard navigation:
- All functionality accessible via keyboard
- Logical tab order
- Focus management in modals
- Skip links for long content
Screen reader support:
- Proper ARIA labels
- Announce dynamic changes (live regions)
- Descriptive alt text
- Semantic HTML
Motion sensitivity:
css
@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}High contrast mode:
- Test in Windows high contrast mode
- Don't rely only on color
- Provide alternative visual cues
键盘导航:
- 所有功能可通过键盘访问
- 合理的Tab顺序
- 模态框中的焦点管理
- 长内容的跳转链接
屏幕阅读器支持:
- 正确的ARIA标签
- 动态内容的实时播报(live regions)
- 描述性的alt文本
- 语义化HTML
动效敏感度适配:
css
@media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}高对比度模式:
- 在Windows高对比度模式下测试
- 不单纯依赖颜色区分
- 提供替代视觉提示
Performance Resilience
性能韧性
Slow connections:
- Progressive image loading
- Skeleton screens
- Optimistic UI updates
- Offline support (service workers)
Memory leaks:
- Clean up event listeners
- Cancel subscriptions
- Clear timers/intervals
- Abort pending requests on unmount
Throttling & Debouncing:
javascript
// Debounce search input
const debouncedSearch = debounce(handleSearch, 300);
// Throttle scroll handler
const throttledScroll = throttle(handleScroll, 100);慢速网络:
- 渐进式图片加载
- 骨架屏
- 乐观UI更新
- 离线支持(Service Workers)
内存泄漏:
- 清理事件监听器
- 取消订阅
- 清除定时器/间隔器
- 组件卸载时终止未完成的请求
节流与防抖:
javascript
// Debounce search input
const debouncedSearch = debounce(handleSearch, 300);
// Throttle scroll handler
const throttledScroll = throttle(handleScroll, 100);Testing Strategies
测试策略
Manual testing:
- Test with extreme data (very long, very short, empty)
- Test in different languages
- Test offline
- Test slow connection (throttle to 3G)
- Test with screen reader
- Test keyboard-only navigation
- Test on old browsers
Automated testing:
- Unit tests for edge cases
- Integration tests for error scenarios
- E2E tests for critical paths
- Visual regression tests
- Accessibility tests (axe, WAVE)
IMPORTANT: Hardening is about expecting the unexpected. Real users will do things you never imagined.
NEVER:
- Assume perfect input (validate everything)
- Ignore internationalization (design for global)
- Leave error messages generic ("Error occurred")
- Forget offline scenarios
- Trust client-side validation alone
- Use fixed widths for text
- Assume English-length text
- Block entire interface when one component errors
手动测试:
- 使用极端数据测试(极长、极短、空内容)
- 在不同语言环境下测试
- 离线测试
- 慢速网络测试(限速至3G)
- 屏幕阅读器测试
- 纯键盘导航测试
- 在旧版浏览器中测试
自动化测试:
- 边缘场景的单元测试
- 错误场景的集成测试
- 关键路径的端到端测试
- 视觉回归测试
- 无障碍测试(axe、WAVE)
重要提示:界面强化的核心是预判意外情况。真实用户会做出你从未设想过的操作。
绝对不要:
- 假设输入数据完美无缺(所有内容都要验证)
- 忽略国际化需求(为全球用户设计)
- 使用模糊的错误提示(如“发生错误”)
- 忘记离线场景
- 仅依赖客户端验证
- 为文本设置固定宽度
- 假设文本长度与英文一致
- 单个组件出错时阻塞整个界面
Verify Hardening
验证界面强化效果
Test thoroughly with edge cases:
- Long text: Try names with 100+ characters
- Emoji: Use emoji in all text fields
- RTL: Test with Arabic or Hebrew
- CJK: Test with Chinese/Japanese/Korean
- Network issues: Disable internet, throttle connection
- Large datasets: Test with 1000+ items
- Concurrent actions: Click submit 10 times rapidly
- Errors: Force API errors, test all error states
- Empty: Remove all data, test empty states
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.
针对边缘场景进行全面测试:
- 长文本:尝试输入100+字符的名称
- 表情符号:在所有文本字段中使用表情符号
- RTL:用阿拉伯语或希伯来语测试
- CJK:用中文/日文/韩文测试
- 网络问题:断开网络、限速连接
- 大型数据集:测试1000+条目的场景
- 并发操作:快速点击提交按钮10次
- 错误场景:强制触发API错误,测试所有错误状态
- 空状态:移除所有数据,测试空状态表现
记住:你是为生产环境的真实场景做强化,而非演示用的完美场景。要预料到用户会输入奇怪的数据、在流程中途断网,以及以意想不到的方式使用你的产品。要将韧性构建到每个组件中。