Set turtle graphics inside runCode to avoid null.firstChild#1428
Merged
cocomarine merged 6 commits intomainfrom Apr 17, 2026
Merged
Set turtle graphics inside runCode to avoid null.firstChild#1428cocomarine merged 6 commits intomainfrom
cocomarine merged 6 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses an intermittent Skulpt Turtle graphics failure (reported as null.firstChild) by ensuring the Turtle graphics target/asset wiring happens before Skulpt imports/executes user code, particularly in the web component (shadow DOM) context.
Changes:
- Initialize
Sk.TurtleGraphics.targetandSk.TurtleGraphics.assetsinsiderunCode()before invokingSk.misceval.asyncToPromise/ importing the main module. - Add a regression test asserting Turtle wiring occurs before
asyncToPromiseis entered.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.jsx | Wires Turtle graphics target/assets earlier (and supports shadowRoot lookup) to prevent null access during turtle import/runtime init. |
| src/components/Editor/Runners/PythonRunner/SkulptRunner/SkulptRunner.test.js | Adds a unit test ensuring Turtle configuration is set before Skulpt execution begins. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
DNR500
approved these changes
Apr 16, 2026
Contributor
DNR500
left a comment
There was a problem hiding this comment.
Nice! I can see how this should avoid a race condition between turtle setup and code execution in VisualOutputPane. Also, thanks for adding the comments and tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes Intermittent ExternalError when running Turtle projects after saving #1261
Findings
turtle.jswithin the skupt module, it seemed that the type error could be coming from thetargetbeing null while checkingtarget.firstChildfor the while loop:SkulptRunnerruns runCode() in a parent useEffect.VisualOutputPanesetsSk.TurtleGraphics.targetin a child useEffect. React runs parent effects before child effects, so from turtle import * can run before the child has setSk.TurtleGraphics.target.Potential fix
Sk.TurtleGraphics.targetpoints at#turtleOutputbefore turtle runs by setting it within the SkulpRunner's runCode()