Skip to content

fix(code-example): handle quote variants and dedupe injected props#938

Open
Utkarsh-Singhal-26 wants to merge 2 commits intoDavidHDev:mainfrom
Utkarsh-Singhal-26:fix/codeexample-prop-quote-dedupe
Open

fix(code-example): handle quote variants and dedupe injected props#938
Utkarsh-Singhal-26 wants to merge 2 commits intoDavidHDev:mainfrom
Utkarsh-Singhal-26:fix/codeexample-prop-quote-dedupe

Conversation

@Utkarsh-Singhal-26
Copy link
Copy Markdown
Contributor

@Utkarsh-Singhal-26 Utkarsh-Singhal-26 commented Apr 5, 2026

Summary

This PR fixes a code-example rendering issue (#937) where the same prop could appear twice in the Usage snippet when quote styles differed.

Problem

Some usage snippets had an existing prop written with single quotes, while dynamic prop updates are generated with double quotes.
Because the matcher did not fully account for both styles, it could fail to detect the existing prop and append a new one, causing duplicates.

Root Cause

The simple prop matcher handled only a subset of value formats and could miss valid single-quoted prop lines.
When matching failed, fallback logic appended a new prop instead of replacing the existing one.

Fix

  • Expanded prop-line matching to support:
    • Single-quoted strings
    • Double-quoted strings
    • Braced values
    • Bare values
  • Added deduplication so if multiple lines for the same prop exist, only one normalized line is kept.

Why This Works

The injector now recognizes equivalent prop lines regardless of quote style and replaces them in place.
If duplicates already exist, deduplication removes extras, preventing repeated props in generated Usage output.

Scope

This change only affects code-example generation.
There is no runtime behavior change to component logic.

Validation

  • Verified no new errors in the modified file.
  • Confirmed duplicate-prop scenarios caused by quote-style mismatch are prevented.

Copilot AI review requested due to automatic review settings April 5, 2026 10:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the code-snippet prop injection logic used by CodeExample so usage strings are updated correctly when props use different quoting styles, and attempts to prevent duplicate injected props from appearing in rendered examples.

Changes:

  • Expands the “simple prop” matching regex to recognize single-quoted and additional value forms.
  • Replaces duplicate matches by keeping only the first occurrence and deleting subsequent occurrences.
  • Adds a newline-collapsing pass after deduplication.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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