Skip to content

🐛 Bug: Falsy check incorrectly treats index 0 as "not found" in JsonEditor component #1920

@shubhamkumar9199

Description

@shubhamkumar9199

Describe the bug

In components/JsonEditor.tsx, the hasCodeblockAsDescendant function is using a falsy check on the value returned by indexOf(). Since indexOf() returns 0 when the match is found at the very beginning of the string, the check treats that valid result as if nothing was found. Because of that, the function exits early whenever the code block appears at the start of the markdown content.

Steps To Reproduce

1.Open a markdown file where a JSON code block appears right at the beginning (index 0).

2.The JsonEditor component starts processing the markdown content.

3.During that process, the hasCodeblockAsDescendant check runs.

4.Since indexOf() returns 0 when it finds the code block at the start, the condition

if (!positionOfCodeInFullMarkdown)
incorrectly evaluates to true.

As a result, the function exits early and skips handling code that should actually be processed.

Expected Behavior

The function should be able to detect and handle code blocks no matter where they appear in the markdown — even when a block starts right at index 0.

Screenshots

N/A — this is a logic-level bug, not a visual issue.

Device Information [optional]

- OS: Windows 10
- Browser: Chrome (latest)
- Version: Current codebase

Are you working on this issue?

Yes

Do you think this work might require an [Architectural Decision Record (ADR)]? (significant or noteworthy)

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is the initial status for an issue that requires triage.🐛 BugIndicates that the issue is a bug or defect.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions