Skip to content

Fix render-helper traverse#686

Merged
feruzm merged 2 commits intodevelopfrom
renderhe
Mar 4, 2026
Merged

Fix render-helper traverse#686
feruzm merged 2 commits intodevelopfrom
renderhe

Conversation

@feruzm
Copy link
Copy Markdown
Member

@feruzm feruzm commented Mar 3, 2026

Summary by CodeRabbit

  • Bug Fixes

    • External links in markdown now render as standardized, styled external-link anchors for clearer visual distinction and consistent behavior.
  • Refactor

    • Improved traversal logic in the markdown renderer to more safely handle complex nested content and DOM mutations during processing.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eefab433-900a-4eba-a70f-37e01378debc

📥 Commits

Reviewing files that changed from the base of the PR and between bd8614a and 16e719a.

⛔ Files ignored due to path filters (6)
  • packages/render-helper/dist/browser/index.js is excluded by !**/dist/**
  • packages/render-helper/dist/browser/index.js.map is excluded by !**/dist/**, !**/*.map
  • packages/render-helper/dist/node/index.cjs is excluded by !**/dist/**
  • packages/render-helper/dist/node/index.cjs.map is excluded by !**/dist/**, !**/*.map
  • packages/render-helper/dist/node/index.mjs is excluded by !**/dist/**
  • packages/render-helper/dist/node/index.mjs.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (2)
  • packages/render-helper/CHANGELOG.md
  • packages/render-helper/package.json
✅ Files skipped from review due to trivial changes (2)
  • packages/render-helper/CHANGELOG.md
  • packages/render-helper/package.json

📝 Walkthrough

Walkthrough

The DOM traversal logic is refactored from index-based iteration to nextSibling-based iteration to safely handle DOM mutations during node processing. The test for external link rendering is updated to verify the new standardized styling applied to external links.

Changes

Cohort / File(s) Summary
Test Updates
packages/render-helper/src/markdown-2-html.spec.ts
Updated test for whitelisted post links: the second anchor now expected to render as an external link with markdown-external-link class and a data-href attribute instead of a plain href.
Traversal Logic
packages/render-helper/src/methods/traverse.method.ts
Refactored traversal to use nextSibling-based loop, tracking next/prev, handling detached nodes and possible replacements, and preserving per-node handlers.
Metadata
packages/render-helper/CHANGELOG.md, packages/render-helper/package.json
Bumped package version to 2.4.20 and added changelog entry referencing the traverse fix.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 I hop through nodes both near and far,
Tracking next and prev — a tiny star,
When children vanish mid‑hop in flight,
I chase replacements through the night,
External links now wear a tiny bow — so neat! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix render-helper traverse' directly corresponds to the main change—converting the traverse method from index-based to nextSibling-based traversal to handle mutations safely, as documented in the changelog entry.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch renderhe

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/render-helper/src/methods/traverse.method.ts (1)

42-51: Single-replacement assumption may miss nodes if handlers insert multiple siblings.

The current logic only traverses the single node found at next.previousSibling (or node.lastChild). If a handler replaces one node with multiple nodes, only the last inserted one is traversed.

If this is intentional (handlers only insert single replacements), the code is correct. Otherwise, consider iterating from prev.nextSibling up to next to traverse all inserted nodes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/render-helper/src/methods/traverse.method.ts` around lines 42 - 51,
The current replacement-detection in traverse only visits a single node
(possibleReplacement), which misses cases where handlers insert multiple sibling
nodes; update the logic in traverse to iterate from prev.nextSibling (or
node.firstChild if prev is null) forward until you reach next (or null) and call
traverse(...) for each inserted sibling found (use the same arguments: forApp,
depth+1, state, parentDomain, seoContext), ensuring you also check parentNode
=== node for each candidate; replace the single possibleReplacement call with
this loop so all inserted siblings are traversed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/render-helper/src/methods/traverse.method.ts`:
- Around line 42-51: The current replacement-detection in traverse only visits a
single node (possibleReplacement), which misses cases where handlers insert
multiple sibling nodes; update the logic in traverse to iterate from
prev.nextSibling (or node.firstChild if prev is null) forward until you reach
next (or null) and call traverse(...) for each inserted sibling found (use the
same arguments: forApp, depth+1, state, parentDomain, seoContext), ensuring you
also check parentNode === node for each candidate; replace the single
possibleReplacement call with this loop so all inserted siblings are traversed.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cde95ff and bd8614a.

📒 Files selected for processing (2)
  • packages/render-helper/src/markdown-2-html.spec.ts
  • packages/render-helper/src/methods/traverse.method.ts

@feruzm feruzm added the patch Bug fixes and patches (1.0.0 → 1.0.1), add this only if any packages/ have patch changes in PR label Mar 4, 2026
@feruzm feruzm merged commit 373b9c2 into develop Mar 4, 2026
1 check passed
@feruzm feruzm deleted the renderhe branch March 4, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Bug fixes and patches (1.0.0 → 1.0.1), add this only if any packages/ have patch changes in PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant