Skip to content

Commit 40a43b8

Browse files
fix(onboarding): restore subtree:true on MutationObserver to fix feed card loading
With subtree:false, feed articles were never detected because they are nested inside a <main> element within .onb-feed-stage. The observer callback now filters to only call observeFeedArticles() when actual <article> elements (or wrappers containing them) are added, which prevents the engagement-animation feedback loop without breaking article detection. Co-authored-by: Tsahi Matsliah <tsahimatsliah@users.noreply.github.com>
1 parent 00a0d70 commit 40a43b8

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

packages/webapp/pages/onboarding-v2.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,17 +524,32 @@ const OnboardingV2Page = (): ReactElement => {
524524

525525
observeFeedArticles();
526526

527-
const mutationObserver = new MutationObserver(() => {
528-
observeFeedArticles();
527+
const mutationObserver = new MutationObserver((mutations) => {
528+
// Only re-observe when actual <article> elements (or wrappers containing
529+
// them) are added. This prevents a feedback loop with the engagement
530+
// animation, which appends <label>/<span> nodes inside articles —
531+
// those additions are ignored because they are not articles themselves.
532+
const hasNewArticles = mutations.some((mutation) =>
533+
Array.from(mutation.addedNodes).some(
534+
(node) =>
535+
node instanceof HTMLElement &&
536+
(node.tagName === 'ARTICLE' || node.querySelector('article')),
537+
),
538+
);
539+
if (hasNewArticles) {
540+
observeFeedArticles();
541+
}
529542
});
530543
const feedContainer =
531544
document.querySelector('.onb-feed-stage') ?? document.body;
532-
// subtree: false — only watch for direct article additions to the feed
533-
// container, not for DOM mutations inside articles (which the engagement
534-
// animation makes, causing a feedback loop with subtree: true).
545+
// subtree: true is required — feed articles are nested several levels deep
546+
// inside .onb-feed-stage (inside a <main> wrapper), so childList-only
547+
// observation on the container itself never fires when articles load.
548+
// The callback above filters to article additions only, preventing the
549+
// feedback loop that previously occurred with the engagement animation.
535550
mutationObserver.observe(feedContainer, {
536551
childList: true,
537-
subtree: false,
552+
subtree: true,
538553
});
539554

540555
return () => {

0 commit comments

Comments
 (0)