[PR #37] [MERGED] Refactor: optimize JavaScript performance and robustness #41

Closed
opened 2026-02-15 17:17:23 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/openclaw/openclaw.ai/pull/37
Author: @HemantSudarshan
Created: 1/31/2026
Status: Merged
Merged: 2/13/2026
Merged by: @steipete

Base: mainHead: main


📝 Commits (3)

  • 19a1bbf refactor: optimize JavaScript performance and robustness
  • 0718d00 chore: clean up redundant lock files
  • 814e080 fix: always cleanup clipboard fallback textarea

📊 Changes

6 files changed (+355 additions, -8435 deletions)

View changed files

📝 .gitignore (+4 -0)
OPTIMIZATIONS_SUMMARY.md (+229 -0)
package-lock.json (+0 -5103)
pnpm-lock.yaml (+0 -3251)
📝 src/layouts/Layout.astro (+1 -1)
📝 src/pages/index.astro (+121 -80)

📄 Description

Pull Request: JavaScript Performance and Robustness Improvements

📋 Summary

This PR optimizes the landing page JavaScript for better performance, reliability, and future-proofing.

🎯 Changes

1. Fixed Deprecated API Usage

  • Before: Using deprecated navigator.platform API
  • After: Modern navigator.userAgentData with fallback
  • Impact: Future-proof against browser deprecation warnings

2. Added Comprehensive Null Safety

  • Added 23+ null checks across all DOM operations
  • Impact: Prevents crashes if HTML elements are missing or renamed
  • Functions improved: updateCommands(), updateVisibility(), event listeners, Easter egg

3. Performance Optimization

  • Cached frequently queried DOM elements (.pm-cmd, .pm-install, .os-cmd, etc.)
  • Before: 4 DOM queries per state update
  • After: 0 DOM queries (using cached references)
  • Impact: Faster state updates, especially on slower devices

4. Removed Dead Code

  • Deleted unused installCmds object (13 lines)
  • Deleted unused osCmds object
  • Impact: Smaller bundle size, cleaner codebase

5. Enhanced Clipboard Functionality

  • Added execCommand fallback for older browsers
  • Added visual error feedback (red flash on failure)
  • Works in HTTP contexts (not just HTTPS)
  • Impact: Better UX, wider browser support

6. Lock File Cleanup

  • Removed package-lock.json and pnpm-lock.yaml
  • Kept bun.lock as primary (per README)
  • Updated .gitignore to prevent future conflicts
  • Impact: Prevents dependency version mismatches

📊 Statistics

Metric Before After Improvement
Deprecated APIs 1 0 Fixed
Null checks 0 23+ Crash-proof
DOM queries/update 4 0 100% cached
Dead code lines 13 0 Cleaned
Browser support Modern only Modern + legacy Wider

🧪 Testing

All changes are backwards compatible and defensive:

  • No breaking changes to existing functionality
  • Graceful degradation for missing DOM elements
  • Clipboard works in more environments
  • OS detection more reliable

📚 Documentation

See OPTIMIZATIONS_SUMMARY.md for detailed before/after code comparisons.

🤔 Discussion Points

  1. Lock file deletion - I chose to keep only bun.lock based on the README. Let me know if you prefer keeping multiple lock files.
  2. Testing - I don't see automated tests in the repo. Should I add some?
  3. Breaking into smaller PRs - Happy to split this into multiple smaller PRs if you prefer.

Checklist

  • Code follows project conventions
  • Changes are backwards compatible
  • Documentation updated (OPTIMIZATIONS_SUMMARY.md)
  • Commit messages follow Conventional Commits
  • No console.log statements (only console.error for legit errors)
  • Self-reviewed the code

Ready for review! Let me know if you'd like any changes or have questions about the approach. 🙌


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/openclaw/openclaw.ai/pull/37 **Author:** [@HemantSudarshan](https://github.com/HemantSudarshan) **Created:** 1/31/2026 **Status:** ✅ Merged **Merged:** 2/13/2026 **Merged by:** [@steipete](https://github.com/steipete) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (3) - [`19a1bbf`](https://github.com/openclaw/openclaw.ai/commit/19a1bbf612c9b8cecb6a1f681e0d8ec0e8b09c13) refactor: optimize JavaScript performance and robustness - [`0718d00`](https://github.com/openclaw/openclaw.ai/commit/0718d00b0cb29dbded20f73b069abad1f896a8a7) chore: clean up redundant lock files - [`814e080`](https://github.com/openclaw/openclaw.ai/commit/814e080423c517d084dd55c8421924075e8a68f9) fix: always cleanup clipboard fallback textarea ### 📊 Changes **6 files changed** (+355 additions, -8435 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+4 -0) ➕ `OPTIMIZATIONS_SUMMARY.md` (+229 -0) ➖ `package-lock.json` (+0 -5103) ➖ `pnpm-lock.yaml` (+0 -3251) 📝 `src/layouts/Layout.astro` (+1 -1) 📝 `src/pages/index.astro` (+121 -80) </details> ### 📄 Description # Pull Request: JavaScript Performance and Robustness Improvements ## 📋 Summary This PR optimizes the landing page JavaScript for better performance, reliability, and future-proofing. ## 🎯 Changes ### 1. Fixed Deprecated API Usage - **Before**: Using deprecated `navigator.platform` API - **After**: Modern `navigator.userAgentData` with fallback - **Impact**: Future-proof against browser deprecation warnings ### 2. Added Comprehensive Null Safety - Added 23+ null checks across all DOM operations - **Impact**: Prevents crashes if HTML elements are missing or renamed - Functions improved: `updateCommands()`, `updateVisibility()`, event listeners, Easter egg ### 3. Performance Optimization - Cached frequently queried DOM elements (`.pm-cmd`, `.pm-install`, `.os-cmd`, etc.) - **Before**: 4 DOM queries per state update - **After**: 0 DOM queries (using cached references) - **Impact**: Faster state updates, especially on slower devices ### 4. Removed Dead Code - Deleted unused `installCmds` object (13 lines) - Deleted unused `osCmds` object - **Impact**: Smaller bundle size, cleaner codebase ### 5. Enhanced Clipboard Functionality - Added `execCommand` fallback for older browsers - Added visual error feedback (red flash on failure) - Works in HTTP contexts (not just HTTPS) - **Impact**: Better UX, wider browser support ### 6. Lock File Cleanup - Removed `package-lock.json` and `pnpm-lock.yaml` - Kept `bun.lock` as primary (per README) - Updated `.gitignore` to prevent future conflicts - **Impact**: Prevents dependency version mismatches ## 📊 Statistics | Metric | Before | After | Improvement | |--------|--------|-------|-------------| | Deprecated APIs | 1 | 0 | ✅ Fixed | | Null checks | 0 | 23+ | ✅ Crash-proof | | DOM queries/update | 4 | 0 | ✅ 100% cached | | Dead code lines | 13 | 0 | ✅ Cleaned | | Browser support | Modern only | Modern + legacy | ✅ Wider | ## 🧪 Testing All changes are backwards compatible and defensive: - ✅ No breaking changes to existing functionality - ✅ Graceful degradation for missing DOM elements - ✅ Clipboard works in more environments - ✅ OS detection more reliable ## 📚 Documentation See `OPTIMIZATIONS_SUMMARY.md` for detailed before/after code comparisons. ## 🤔 Discussion Points 1. **Lock file deletion** - I chose to keep only `bun.lock` based on the README. Let me know if you prefer keeping multiple lock files. 2. **Testing** - I don't see automated tests in the repo. Should I add some? 3. **Breaking into smaller PRs** - Happy to split this into multiple smaller PRs if you prefer. ## ✅ Checklist - [x] Code follows project conventions - [x] Changes are backwards compatible - [x] Documentation updated (`OPTIMIZATIONS_SUMMARY.md`) - [x] Commit messages follow Conventional Commits - [x] No console.log statements (only console.error for legit errors) - [x] Self-reviewed the code --- **Ready for review!** Let me know if you'd like any changes or have questions about the approach. 🙌 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 17:17:23 -05:00
yindo closed this issue 2026-02-15 17:17:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: openclaw/openclaw.ai#41