Persist loaded code locally#76
Merged
Merged
Conversation
and refactor internal implementation
There was a problem hiding this comment.
Pull request overview
This PR adds client-side persistence for code loaded via loadSrc and POSTed source, storing it in localStorage keyed by a SHA-256 hash and updating the URL to use that hash. It also enables the standalone runner to load code directly from localStorage based on the URL hash, and factors the loadSrc fetch flow into shared helpers.
Changes:
- Add shared helpers to (a) fetch
loadSrcand strip it from the URL, (b) save code tolocalStorageand update the URL hash, and (c) load code fromlocalStorageby hash. - Update the editor (
codeworld.js) and runner (run.js) initialization flows to use these helpers and persist loaded code. - Adjust the
run(...)API to take a success boolean instead of a code hash, since the URL hash is now updated by the persistence helper.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
web/run.html |
Adds required CSS and jQuery so the runner can initialize alerts (SweetAlert loader depends on jQuery). |
web/js/run.js |
Loads code from localStorage by hash and persists any externally loaded source before compiling. |
web/js/codeworld.js |
Uses shared persistence/fetch helpers, loads saved code by hash, and updates run(...) usage. |
web/js/codeworld_shared.js |
Introduces persistence + fetch helpers and changes the run(...) signature/behavior. |
Comments suppressed due to low confidence (1)
web/js/codeworld_shared.js:1148
tryFetchCodeFromSourceAndStripURLdoesn’tawaitthe provided handler. Callers currently pass anasynchandler (e.g. incodeworld.js), but because it’s not awaited any thrown errors become unhandled rejections and the caller can’t rely on the handler’s side effects (like saving/updating the URL) having completed whentryFetch...resolves. Considerawait handler(code)and/or returning the fetched code instead of using a callback.
const code = await response.text();
searchParams.delete("loadSrc");
window.history.replaceState(window.history.state, "", currentUrl.toString());
sweetAlert.close();
handler(code);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
patritzenfeld
approved these changes
May 15, 2026
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.
The client will now store the code loaded via
loadSrcand POST requests in its local storage. TheloadSrcURL parameter is then stripped and the code hash appended to the URL.It is now also possible to load a program from local storage when using the runner directly.
(As discussed in #36 (comment))