Skip to content

feat(VB-2354): notify the editor when the entries on the page change - #648

Open
sairaj-cs wants to merge 1 commit into
develop_v4from
VB-2354-entries-in-page-changed
Open

sairaj-cs wants to merge 1 commit into
develop_v4from
VB-2354-entries-in-page-changed

Conversation

@sairaj-cs

@sairaj-cs sairaj-cs commented Sep 11, 2026

Copy link
Copy Markdown

Summary

The SDK now tells the editor which entries are on the page and pushes an update whenever that set changes. Until now the editor had to ask for the list and hope it was still current. Late-rendered references (lazy sections, client-side fetches) never reached it.

Changes

  • New ENTRIES_IN_PAGE_CHANGED post-message event, sent once the builder is ready and again from the existing body MutationObserver whenever the set of entry+locale pairs on the page changes.
  • getEntryIdentifiersInCurrentPage dedups by entry and locale and exposes a signature so the observer only posts on a real change.
  • No change to existing events or to the public API.

Test plan

  • npm test -- getEntryIdentifiersInCurrentPage covers dedup and the signature.
  • Tested locally against the matching editor branch with the CSR test site: the editor receives the event once on load, again when late-rendered blog cards mount, and again when a card is removed from the DOM. Each change opened or closed exactly the channels for the entries that changed.

🤖 Generated with Claude Code

Send entries-in-page-changed once the builder is ready and again from the
body MutationObserver whenever the entry+locale set on the page changes, so
the editor can react to late-rendered references without polling. Dedup the
page scan by entry and locale.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@sairaj-cs
sairaj-cs requested a review from a team as a code owner September 11, 2026 09:09
@snyk-io

snyk-io Bot commented Sep 11, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 0 25 ✅ Passed
🟡 Medium Severity 0 0 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

✅ BUILD PASSED - All security checks passed

@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 67.49% 2539 / 3762
🔵 Statements 66.35% 2580 / 3888
🔵 Functions 64.86% 456 / 703
🔵 Branches 62.01% 1533 / 2472
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/visualBuilder/index.ts 55.63% 28.76% 35.29% 55.31% 104-110, 114-117, 122-131, 137-207, 229-263, 273-294, 348-350, 354, 409-412
src/visualBuilder/utils/getEntryIdentifiersInCurrentPage.ts 100% 100% 100% 100%
Generated in workflow #907 for commit 751dd41 by the Vitest Coverage Report Action

@sairaj-cs sairaj-cs changed the title feat: notify the editor when the entries on the page change feat(VB-2354): notify the editor when the entries on the page change Sep 15, 2026

@kirtesh-cstk kirtesh-cstk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed alongside visual-builder#2717. The direction is right and the push carries its payload, which is already better than the send-variant-and-locale pattern it sits next to (that one pings, then the editor sends two more messages back). Comments below are one naming call and two edge cases. Nothing blocking the approach.


// FROM visual builder
GET_ALL_ENTRIES_IN_CURRENT_PAGE = "get-entries-in-current-page",
ENTRIES_IN_PAGE_CHANGED = "entries-in-page-changed",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this entries-in-current-page-changed?

get- is the request/response prefix everywhere in this enum, and each of those is a .send() that awaits a value. Push notifications use the unprefixed past-tense form (composition-saved, primary-composition-detected). Matching get-entries-in-current-page on the noun also makes the pair obvious when reading the enum.

Worth settling now: this string is the wire contract on an SDK that customers pin, so renaming after release means supporting both forever.

this.visualBuilderContainer,
this.resizeObserver
);
this.notifyEntriesInPageIfChanged();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The observer is { childList: true, subtree: true }, so attribute-only changes never reach notifyEntriesInPageIfChanged.

useRecalculateVariantDataCSLPValues rewrites data-cslp in place on a variant switch. Same nodes, different entry uids, no mutation record, no push. The editor would keep the old entries' channels and miss the new ones.

Either add attributes: true, attributeFilter: ["data-cslp"] to the observe call, or call notifyEntriesInPageIfChanged() at the end of the recalculation path.

locale: cslpData.locale
}
);
uniqueEntriesMap.set(`${cslpData.entry_uid}.${cslpData.locale}`, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dedup key moved from entry_uid to entry_uid.locale, which changes what the existing get-entries-in-current-page response returns, not just the new event. On a page rendering one entry in two locales, every current caller now gets that entry twice.

Correct for channel subscriptions, but the callers were written against the old shape. Worth a check on EntryAccordionList and ContentPublishModal before this ships, since a duplicate in the publish list is the expensive kind of surprise. If they are not locale-aware, the signature could key on entry+locale while the response stays deduped by uid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants