Fix null when accessing document.body#3483
Conversation
Add optional chaining (?.) and nullish coalescing (|| 0) when accessing document.body.scrollLeft and document.body.scrollTop to prevent TypeError when document.body is temporarily null during heavy DOM manipulation or aggressive reflows. Fixes #3348
Pull Request ReviewThanks for addressing issue #3348! This is a solid defensive fix for a rare but real edge case. Here's my detailed review: ✅ Code Quality & Best PracticesStrengths:
📝 Test QualityThe test file is comprehensive and well-written:
Test structure strengths:
🔍 Potential Issues & Concerns1. Test implementation concern (Minor)The test uses Expected pattern: // DocumentProjectionNode is a class returned by createProjectionNode
const node = new DocumentProjectionNode()Or if there's a factory: // If there's a create method on the class
const node = DocumentProjectionNode.create(window)Recommendation: Please verify the tests actually run and pass. If they don't compile/run, the instantiation pattern needs correction. 2. Edge case consideration (Very Minor)The current implementation: x: document.documentElement.scrollLeft || document.body?.scrollLeft || 0This works correctly, but there's a subtle difference between
The logic is correct for the use case, just documenting the behavior. 🔒 Security ConcernsNone identified. This is a defensive null check with no security implications. ⚡ Performance ConsiderationsExcellent - no performance impact:
🧪 Test CoverageStrong coverage for the specific bug fix:
Possible additional test (optional):
📋 Summary & RecommendationThis is a high-quality defensive fix that addresses a real production issue. The implementation is clean, minimal, and follows best practices. Before merging, please verify:
Rating: 9/10 - Excellent fix with comprehensive tests. Only concern is verifying the test instantiation pattern is valid. 🎯 Specific Questions for Author
Great work on fixing this rare but important edge case! 🚀 |
Test the measureScroll logic directly rather than trying to instantiate DocumentProjectionNode, which requires complex setup.
PR Review: Fix
|
Add optional chaining (?.) and nullish coalescing (|| 0) when accessing document.body.scrollLeft and document.body.scrollTop to prevent TypeError when document.body is temporarily null during heavy DOM manipulation or aggressive reflows.
Fixes #3348