Skip to content

Fix running a newly selected example with stale editor code - #313

Merged
mxschmitt merged 3 commits into
mainfrom
cursor/stale-example-code-7b47
Sep 3, 2026
Merged

mxschmitt merged 3 commits into
mainfrom
cursor/stale-example-code-7b47

Conversation

@mxschmitt

@mxschmitt mxschmitt commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Why

Selecting an example and clicking Run in the same tick sent the previous editor buffer to /run. Example 8 (video) could still execute the default screenshot snippet, so e2e saw 0 videos and leftover example-chromium.png / example-webkit.png.

React setState is async: onChange updates context, but handleExecution still closed over code from the last render. That is worse after await Turnstile.

The setter-written ref is not duplicated state — it is the mailbox React recommends for reading the latest value from an async handler. A useEffect copy is still stale in the same click. Characterization only: #316

What

  • updateCode writes latestCode then setCode.
  • Run calls getCode() after the Turnstile promise.
  • e2e clicks the example link, waits for .rs-panel-in, then Run.

Does not change Turnstile or /run streaming.

Test plan

Open in Web Open in Cursor 

Clicking an example and Run in the same tick used React state from the
previous render, so example 8 could still execute the default screenshot
snippet. Keep the latest code in a ref, read it via getCode() on Run,
and wait for the examples accordion to open before clicking Run in e2e.

Co-authored-by: Max Schmitt <max@schmitt.mx>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-03T01:43:52.497511Z 18d8fc8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 18d8fc8f9a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

});
});
setResponse(await runCode(code, codeLanguage, turnstileToken))
setResponse(await runCode(getCode(), codeLanguage, turnstileToken))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Snapshot the code before awaiting Turnstile

When Turnstile completion is delayed and the user selects another example from the still-active examples panel after clicking Run, getCode() reads the mutated ref only after that selection, so this execution unexpectedly submits the later example rather than the code associated with the Run click. Capture getCode() before awaiting the Turnstile token, then pass that snapshot to runCode.

Useful? React with 👍 / 👎.

cursoragent and others added 2 commits September 3, 2026 01:49
The setter-written ref is the product fix; the characterization test
lives in a separate repro PR so this change stays the App/e2e path.

Co-authored-by: Max Schmitt <max@schmitt.mx>
Co-authored-by: Max Schmitt <max@schmitt.mx>
@mxschmitt
mxschmitt merged commit 90009f1 into main Sep 3, 2026
12 checks passed
@mxschmitt
mxschmitt deleted the cursor/stale-example-code-7b47 branch September 3, 2026 02:07
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