🐛(frontend) fix outlook web handler in unquote logic#754
Conversation
📝 WalkthroughWalkthroughMicrosoft Outlook Web quote detection now climbs nested wrappers before collecting quote siblings. Outlook Desktop detection recognizes wrapped ChangesOutlook quote detection
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/frontend/src/features/utils/unquote-message/handlers.ts`:
- Around line 155-160: Update the sibling detection around msoRoot to inspect
parentElement.childNodes so plain-text nodes are included, but only consider
nodes positioned before msoRoot. Preserve the existing non-empty text check via
trimmed textContent and break when a preceding sibling contains content,
avoiding quoted nodes that follow msoRoot.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: c185b923-67b7-4034-b13a-ee888e256175
📒 Files selected for processing (2)
src/frontend/src/features/utils/unquote-message/handlers.tssrc/frontend/src/features/utils/unquote-message/index.test.ts
About the unquote-message logic, we encount a bug with a thread implying Outlook Desktop quotes. Actually, for Outlook web we were looking for a hr tag as quote separtor element. But sometimes this one can be wrap into a div and we missed it.
6f83b71 to
7b2528b
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/frontend/src/features/utils/unquote-message/handlers.ts`:
- Around line 158-169: Update the preceding-sibling check in the unquote-message
traversal to walk backward from msoRoot.previousSibling using previousSibling,
stopping when a qualifying ELEMENT_NODE or non-empty TEXT_NODE is found. Remove
the siblings Array.from and previousSiblings.slice allocations while preserving
the existing break behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: ac70cdeb-0dcf-4c39-a68c-19844bbbb335
📒 Files selected for processing (2)
src/frontend/src/features/utils/unquote-message/handlers.tssrc/frontend/src/features/utils/unquote-message/index.test.ts
| const siblings = Array.from(msoRoot.parentElement.childNodes); | ||
| const previousSiblings = siblings.slice(0, siblings.indexOf(msoRoot)); | ||
| if ( | ||
| previousSiblings.some( | ||
| (node) => | ||
| (node.nodeType === Node.ELEMENT_NODE || | ||
| node.nodeType === Node.TEXT_NODE) && | ||
| node.textContent?.trim() | ||
| ) | ||
| ) { | ||
| break; | ||
| } |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value
Optimize preceding sibling traversal to avoid array allocations.
Instead of creating intermediate arrays for all child nodes and slicing them on every climb iteration, you can traverse backwards using previousSibling. This avoids O(N) array allocations within the loop while achieving the same logic.
♻️ Proposed refactor
- const siblings = Array.from(msoRoot.parentElement.childNodes);
- const previousSiblings = siblings.slice(0, siblings.indexOf(msoRoot));
- if (
- previousSiblings.some(
- (node) =>
- (node.nodeType === Node.ELEMENT_NODE ||
- node.nodeType === Node.TEXT_NODE) &&
- node.textContent?.trim()
- )
- ) {
- break;
- }
+ let hasMeaningfulContent = false;
+ let current = msoRoot.previousSibling;
+
+ while (current) {
+ if (
+ (current.nodeType === Node.ELEMENT_NODE ||
+ current.nodeType === Node.TEXT_NODE) &&
+ current.textContent?.trim()
+ ) {
+ hasMeaningfulContent = true;
+ break;
+ }
+ current = current.previousSibling;
+ }
+
+ if (hasMeaningfulContent) {
+ break;
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const siblings = Array.from(msoRoot.parentElement.childNodes); | |
| const previousSiblings = siblings.slice(0, siblings.indexOf(msoRoot)); | |
| if ( | |
| previousSiblings.some( | |
| (node) => | |
| (node.nodeType === Node.ELEMENT_NODE || | |
| node.nodeType === Node.TEXT_NODE) && | |
| node.textContent?.trim() | |
| ) | |
| ) { | |
| break; | |
| } | |
| let hasMeaningfulContent = false; | |
| let current = msoRoot.previousSibling; | |
| while (current) { | |
| if ( | |
| (current.nodeType === Node.ELEMENT_NODE || | |
| current.nodeType === Node.TEXT_NODE) && | |
| current.textContent?.trim() | |
| ) { | |
| hasMeaningfulContent = true; | |
| break; | |
| } | |
| current = current.previousSibling; | |
| } | |
| if (hasMeaningfulContent) { | |
| break; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/frontend/src/features/utils/unquote-message/handlers.ts` around lines 158
- 169, Update the preceding-sibling check in the unquote-message traversal to
walk backward from msoRoot.previousSibling using previousSibling, stopping when
a qualifying ELEMENT_NODE or non-empty TEXT_NODE is found. Remove the siblings
Array.from and previousSiblings.slice allocations while preserving the existing
break behavior.
Purpose
About the unquote-message logic, we encount a bug with a thread implying Outlook Desktop quotes. Actually, for Outlook web we were looking for a hr tag as quote separtor element. But sometimes this one can be wrap into a div and we missed it.
Summary by CodeRabbit