Skip to content

Improve HTML previews for syntax-highlighted code blocks#461

Closed
aidenybai wants to merge 15 commits into
mainfrom
cursor/improve-html-preview-15a8
Closed

Improve HTML previews for syntax-highlighted code blocks#461
aidenybai wants to merge 15 commits into
mainfrom
cursor/improve-html-preview-15a8

Conversation

@aidenybai

@aidenybai aidenybai commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add descendant text fallback only for the needed text-wrapper preview tags (a, pre, and code)
  • Keep structural container previews compact by showing child summaries only when no preview text is available
  • Add low-signal trace heuristics that append a unique selector hint when source context is missing, package-led, or otherwise not trusted
  • Keep getStackContext trace-only; selector hints are appended only by higher-level element reference/context formatters
  • Prefer stable link/media attributes like href and src when generating selector hints
  • Extract preview text collection into a focused utility that skips hidden/decorative text, including hidden selected roots, and preserves mixed inline text
  • Simplify selector-hint trace logic to a direct boolean instead of carrying a first-signal-kind model
  • Add E2E regressions for Shiki-style syntax-highlighted code blocks, nested/sidebar link labels with selector hints, hidden selected roots, and mixed inline content

Verification

  • Pending re-run after minimal cleanup
Open in Web Open in Cursor 

Summary by cubic

Improved HTML previews now include real text for Shiki-style pre/code blocks and nested link labels, keep containers compact, and add selector hints for low-signal traces.

  • Bug Fixes

    • Extract descendant text for a, pre, code; collapse whitespace; handle mixed inline content; truncate; skip hidden/decorative roots. Show child summaries only when no preview text.
    • Simplify selector-hint rules: append when the trace starts low-signal or no trusted source exists; prefer href/src; cap at 160 chars. Fix link preview formatting. Add E2E for code blocks, nested link labels, hidden roots, and mixed inline content.
  • Refactors

    • Return a typed trace context with a shouldAppendSelectorHint flag and append hints outside stack formatting. Add getElementReferenceContext and use it in the copy flow for bracketed refs.
    • Centralize preview text in getPreviewTextContent and minimize policy changes by limiting descendant-text extraction to a, pre, and code.

Written for commit 39e0b55. Summary will update on new commits.

Review in cubic

Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
@vercel

vercel Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-grab-storybook Ready Ready Preview, Comment Jun 7, 2026 9:29am
react-grab-website Ready Ready Preview, Comment Jun 7, 2026 9:29am

@pkg-pr-new

pkg-pr-new Bot commented Jun 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@react-grab/cli@461
npm i https://pkg.pr.new/grab@461
npm i https://pkg.pr.new/react-grab@461

commit: 39e0b55

Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Comment thread packages/react-grab/src/core/context.ts

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 2 files

Re-trigger cubic

Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Comment thread packages/react-grab/src/core/context.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 4 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/react-grab/src/core/context.ts Outdated
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 5 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/react-grab/src/utils/get-preview-text-content.ts
hasTrustedSource: false,
};
};

@vercel vercel Bot Jun 7, 2026

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.

getStackContext function missing selector hints for low-signal traces (untrusted sources, packages, or servers), causing disambiguation information to be dropped

Fix on Vercel

Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/react-grab/src/core/context.ts Outdated
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e648c55. Configure here.

Comment thread packages/react-grab/src/utils/get-preview-text-content.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/react-grab/src/utils/get-preview-text-content.ts Outdated
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
@cubic-dev-ai

cubic-dev-ai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

You're iterating quickly on this pull request. To help protect your rate limits, cubic has paused automatic reviews on new pushes for now—when you're ready for another review, comment @cubic-dev-ai review.

if (directText && element.children.length === 0) return directText;

const parts: string[] = [];
for (const childNode of element.childNodes) {

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.

Commit 39e0b55 drastically reduced descendant text collection from 28 semantic tags to just 3 tags (a, code, pre), breaking text extraction for elements like h1-h6, button, label, p, span, and other semantic elements

Fix on Vercel

aidenybai added a commit that referenced this pull request Jun 7, 2026
# Conflicts:
#	packages/react-grab/src/core/context.ts
#	packages/react-grab/src/core/copy.ts
aidenybai added a commit that referenced this pull request Jun 7, 2026
Folding in #461 changed formatStackContext to return a typed trace
context ({ text, shouldAppendSelectorHint }); assert against .text.
@aidenybai

Copy link
Copy Markdown
Owner Author

Closing as superseded. This work has already landed on main via #446 (Resolve grabs to app source instead of UI library wrappers) and #444 (Deslop core, delete dead code), in a more complete form:

  • get-preview-text-content.ts already exists on main with the tag sets extracted into constants.ts (PREVIEW_DESCENDANT_TEXT_TAGS / PREVIEW_SKIPPED_TEXT_TAGS) and a character-budget optimization that stops walking large syntax-highlighted subtrees early. This branch's version would regress both.
  • create-element-selector.ts on main already includes href/src in the preferred selector attributes.
  • context.ts on main already has TraceContextResult, composeElementContext, getElementReferenceContext, shouldAppendSelectorHint, and resolveLeadingSource (origin === "app").
  • All four new E2E tests here (syntax-highlighted code blocks, nested link labels, hidden selected roots, mixed inline content) are already present on main.

The branch's merge-base with main is from June 4; rebasing produces 15 commits of conflicts that would only re-introduce the older implementation. Nothing left to merge.

@aidenybai aidenybai closed this Jun 14, 2026
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