Skip to content

fix: define renderCodeWithLineNumbers in script.js to resolve ReferenceError#436

Open
anshul23102 wants to merge 1 commit into
komalharshita:mainfrom
anshul23102:fix/render-code-with-line-numbers
Open

fix: define renderCodeWithLineNumbers in script.js to resolve ReferenceError#436
anshul23102 wants to merge 1 commit into
komalharshita:mainfrom
anshul23102:fix/render-code-with-line-numbers

Conversation

@anshul23102
Copy link
Copy Markdown
Contributor

@anshul23102 anshul23102 commented May 22, 2026

Description

The code viewer panel on detail pages called renderCodeWithLineNumbers(data.code) but this function was never defined anywhere in the codebase. Every click on the View Code or View Code (mobile) button threw a ReferenceError in the browser console and the code panel rendered empty.

Root Cause

renderCodeWithLineNumbers(data.code).forEach(function (row) {
  codeContentEl.appendChild(row);
});
// renderCodeWithLineNumbers is called here but was never defined

Related Issue

Closes #406

Type of Change

  • Bug fix

Changes Made

  • static/script.js:
    • Added renderCodeWithLineNumbers(code) function inside the detail-page block, adjacent to fetchStarterCode.
    • The function splits the code string into lines and returns an array of DOM row elements, each containing a line-number gutter cell (.code-line-number) and a content cell (.code-line-content).
    • Uses document.createElement and textContent instead of innerHTML so the code content is never parsed as markup.

Testing Done

  1. Click View Code on a project detail page: code panel opens and displays code with line numbers.
  2. Code containing HTML special characters renders as plain text, not markup.
  3. Empty code string: renders zero rows without errors.

Checklist

  • My code follows the style and formatting of this project
  • I have tested my changes locally and they work as expected
  • There are no merge conflicts with the base branch
  • This PR is linked to the correct issue

@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

@anshul23102 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

@anshul23102
Copy link
Copy Markdown
Contributor Author

@komalharshita this PR is ready for review and all CI checks pass. Could you please add the relevant labels? It helps with tracking. Thank you!

@anshul23102
Copy link
Copy Markdown
Contributor Author

Hi @komalharshita, just a gentle follow-up on this PR. It has been about 5 days and the branch is clean with no CI failures or conflicts. Please let me know if you would like any changes. Thank you for your time!

@komalharshita komalharshita added need review Further information is requested level:beginner quality:clean labels Jun 2, 2026
Copy link
Copy Markdown
Owner

@komalharshita komalharshita left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution.

I reviewed the changes and verified that this PR directly addresses the reported ReferenceError caused by the missing renderCodeWithLineNumbers() function.

The implementation is focused, follows the existing DOM structure and CSS class conventions, and safely renders code content using textContent. This restores the View Code functionality and prevents the runtime error from occurring when opening starter code panels.

The fix is clear, low-risk, and scoped appropriately to the linked issue.

Looks good to me and is ready to be merged after resolving the merge conflicts with the latest main branch.

…or on detail pages

The code viewer panel called renderCodeWithLineNumbers(data.code) at line
763 of script.js, but this function was never defined anywhere in the
codebase. Every click on the View Code or View Code (mobile) button
produced a ReferenceError in the browser console and the code panel
rendered empty.

Add renderCodeWithLineNumbers(code) adjacent to fetchStarterCode. It
splits the code string into lines and returns an array of DOM row elements,
each containing a line-number gutter cell and a content cell. Using
document.createElement and textContent instead of innerHTML ensures the
code content is never parsed as markup.

Closes komalharshita#406
@anshul23102 anshul23102 force-pushed the fix/render-code-with-line-numbers branch from d131abd to f8d5f42 Compare June 2, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ReferenceError: renderCodeWithLineNumbers is not defined in script.js

2 participants