-
Notifications
You must be signed in to change notification settings - Fork 1
fix(discussions): emit REQUEST_DISCUSSION_HIGHLIGHTS when iframe CSLPs mutate #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
karancs06
wants to merge
1
commit into
develop_v4
Choose a base branch
from
fix/discussion-comment-variant-cslp-highlight
base: develop_v4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/visualBuilder/generators/__test__/generateHighlightedComment.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { describe, it, expect, beforeEach, afterEach } from "vitest"; | ||
| import { | ||
| updateHighlightedCommentIconPosition, | ||
| removeAllHighlightedCommentIcons, | ||
| } from "../generateHighlightedComment"; | ||
|
|
||
| describe("updateHighlightedCommentIconPosition", () => { | ||
| let container: HTMLDivElement; | ||
|
|
||
| beforeEach(() => { | ||
| container = document.createElement("div"); | ||
| container.className = "visual-builder__container"; | ||
| document.body.appendChild(container); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| document.body.removeChild(container); | ||
| }); | ||
|
|
||
| const makeIcon = (fieldPath: string): HTMLDivElement => { | ||
| const icon = document.createElement("div"); | ||
| icon.className = "highlighted-comment collab-icon"; | ||
| icon.setAttribute("field-path", fieldPath); | ||
| icon.style.position = "fixed"; | ||
| icon.style.top = "100px"; | ||
| icon.style.left = "200px"; | ||
| container.appendChild(icon); | ||
| return icon; | ||
| }; | ||
|
|
||
| const makeTarget = (cslpValue: string): HTMLDivElement => { | ||
| const el = document.createElement("div"); | ||
| el.setAttribute("data-cslp", cslpValue); | ||
| container.appendChild(el); | ||
| return el; | ||
| }; | ||
|
|
||
| it("keeps an icon whose target element is still present", () => { | ||
| const cslp = "content.entry.en-us.field"; | ||
| makeTarget(cslp); | ||
| makeIcon(cslp); | ||
|
|
||
| updateHighlightedCommentIconPosition(); | ||
|
|
||
| expect( | ||
| document.querySelector(`.highlighted-comment[field-path="${cslp}"]`), | ||
| ).not.toBeNull(); | ||
| }); | ||
|
|
||
| it("removes an orphaned icon when its target element is no longer found", () => { | ||
| // Stale CSLP with no matching element — simulates the element having | ||
| // been mutated to a variant CSLP value. | ||
| const staleCslp = "content.entry.en-us.old_field"; | ||
| makeIcon(staleCslp); | ||
|
|
||
| updateHighlightedCommentIconPosition(); | ||
|
|
||
| expect( | ||
| document.querySelector(`.highlighted-comment[field-path="${staleCslp}"]`), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("removes only orphaned icons and keeps valid ones", () => { | ||
| const validCslp = "content.entry.en-us.valid"; | ||
| const staleCslp = "content.entry.en-us.stale"; | ||
|
|
||
| makeTarget(validCslp); | ||
| makeIcon(validCslp); | ||
| makeIcon(staleCslp); | ||
|
|
||
| updateHighlightedCommentIconPosition(); | ||
|
|
||
| expect( | ||
| document.querySelector(`.highlighted-comment[field-path="${validCslp}"]`), | ||
| ).not.toBeNull(); | ||
| expect( | ||
| document.querySelector(`.highlighted-comment[field-path="${staleCslp}"]`), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("does not throw when there are no icons", () => { | ||
| expect(() => updateHighlightedCommentIconPosition()).not.toThrow(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("removeAllHighlightedCommentIcons", () => { | ||
| it("removes every .highlighted-comment element", () => { | ||
| ["a", "b", "c"].forEach((cslp) => { | ||
| const icon = document.createElement("div"); | ||
| icon.className = "highlighted-comment collab-icon"; | ||
| icon.setAttribute("field-path", cslp); | ||
| document.body.appendChild(icon); | ||
| }); | ||
|
|
||
| expect(document.querySelectorAll(".highlighted-comment").length).toBe(3); | ||
|
|
||
| removeAllHighlightedCommentIcons(); | ||
|
|
||
| expect(document.querySelectorAll(".highlighted-comment").length).toBe(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can debounce it right? I don't want us to spam, postmessages from LP SDK through mutation observer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's already debounced —
requestDiscussionHighlightsschedules a single 200ms timer (DISCUSSION_HIGHLIGHTS_DEBOUNCE_MS) and resets it on every observed mutation, so a burst ofdata-cslpmutations from a CSR re-render coalesces into exactly one postMessage. See lines 14–17 (constant) and 47–57 (debounce wrapper) in this file.If you'd prefer a longer window (say 300ms or 500ms) for extra safety against very chunky React renders, easy to bump.