Skip to content

Conversation

@pearmini
Copy link
Collaborator

@pearmini pearmini commented Oct 17, 2025

close #170

@ChloeYanYan She reported the following code crashes the browser and no way to open the notebook:

let height = 5;
let triangle = '';

for (let i = 1; i <= height; i++) {
  triangle += ' '.repeat(height - i); 
  triangle += '*'.repeat(i * 2 - 1); 
  triangle += '\n';
}

echo(triangle);

This is because we don't handle top-level non function statement correctly, such as for statement. This PR introduces a way to fix it.

Also, in oder to prevent crashing the browser because of editor, we'll unexpected error and ask users to open console for details by alerts.

@vercel
Copy link

vercel bot commented Oct 17, 2025

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

Project Deployment Preview Comments Updated (UTC)
recho-notebook Ready Ready Preview Comment Oct 17, 2025 8:42pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@pearmini pearmini changed the title Fix crash Fix crash caused by editor Oct 17, 2025
@pearmini pearmini requested a review from Copilot October 17, 2025 20:28
Copy link
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

Fixes a browser crash when executing top-level non-function statements (e.g., for loops) by making evaluation resilient and surfacing errors to users without breaking the editor.

  • Add safeEval fallback to wrap non-function code in a function
  • Add editor-level error handling with a debounced alert and wire it through createEditor
  • Add tests for special statements and minor link/navigation fixes

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
runtime/index.js Adds try/catch and wraps non-function code in a function before evaluation.
editor/index.js Accepts onError and wraps run() in try/catch to surface errors.
app/Editor.jsx Introduces a debounced default onError (alert) and passes onError to the editor.
app/SafeLink.jsx Removes redundant preventDefault in SafeLink click handler.
app/Nav.jsx Uses a plain anchor for external navigation to recho.dev.
test/js/special-statement.js Adds code sample exercising top-level for/if statements.
test/js/index.js Exports specialStatement test input.
test/js/index-tests.js Exports specialStatement tests.
test/output/specialStatement.js Adds expected output fixture for special statement behavior.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pearmini pearmini merged commit 87fb437 into main Oct 17, 2025
3 checks passed
@pearmini pearmini deleted the fix-crash branch October 17, 2025 20:43
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.

Page crashes when trying to open it

2 participants