Fix emoji loading inefficiency and 404 errors#70
Conversation
- Add emoji-resolver.js that loads filename mappings from API - Replace hardcoded .png/.gif extensions with placeholder images - Eliminate 404 errors by using correct extensions from the start - Support any file extension (.png, .gif, .jpg, .webp, etc.) - Maintain backward compatibility for existing data The resolver loads once, caches the mappings, and updates all emoji images with their correct filenames, preventing unnecessary 404s. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Use placeholder images in emoji picker initially - Load actual images after a frame to prevent race conditions - Properly handle URL-encoded filenames like se%C3%B1or-bufo.png
Code Review for PR #70: Fix emoji loading inefficiency and 404 errors✅ Strengths
🔍 Areas of Concern1. Race Condition Risk 🟡In templates/status.html:2257, using requestAnimationFrame to delay image loading might not guarantee the resolver is initialized: requestAnimationFrame(() => {
img.src = `/emojis/${emoji.filename}`;
});Recommendation: Wait for the resolver to be ready: if (window.EmojiResolver) {
window.EmojiResolver.loadEmojiMap().then(() => {
img.src = `/emojis/${emoji.filename}`;
});
}2. Missing Cache Invalidation 🟡The emoji map is cached indefinitely. If emojis are added/removed, users need to refresh to see changes. 3. Security: No Input Sanitization 🔴The emoji names from data-emoji-name attributes aren't sanitized before building URLs in emoji-resolver.js:45 and :52 const sanitizedName = emojiName.replace(/[^a-zA-Z0-9_-]/g, '');4. Memory Leak Potential 🟡The MutationObserver never disconnects, which could cause issues in single-page apps. window.EmojiResolver.cleanup = () => observer.disconnect();📊 Performance Considerations
🔒 Security Review
🧪 Test CoverageCurrently no test coverage for this feature. Recommend adding:
💡 Additional Suggestions
✨ Overall AssessmentThis is a solid improvement that effectively solves the 404 issue. The code is well-structured and handles most edge cases. With the security fix for input sanitization and some minor improvements, this will be production-ready. Verdict: Approve with minor changes ✅ Great work on eliminating those pesky 404s! The placeholder approach is particularly clever. 🎉 |
Summary
se%C3%B1or-bufo.png)Problem
The app was making unnecessary requests that resulted in 404s:
.pngfirst, then falling back to.gifon errorSolution
emoji-resolver.jsthat loads the emoji mapping from/api/custom-emojisonceTest Results
Before: Multiple 404 errors in console when loading pages with emojis
After: Zero 404 errors - all emojis load correctly on first try
🤖 Generated with Claude Code