Skip to content

Persist loaded code locally#76

Merged
patritzenfeld merged 3 commits into
fmidue:fmiduefrom
nimec01:code-less-links
May 15, 2026
Merged

Persist loaded code locally#76
patritzenfeld merged 3 commits into
fmidue:fmiduefrom
nimec01:code-less-links

Conversation

@nimec01
Copy link
Copy Markdown
Collaborator

@nimec01 nimec01 commented May 13, 2026

The client will now store the code loaded via loadSrc and POST requests in its local storage. The loadSrc URL 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))

and refactor internal implementation
Copy link
Copy Markdown

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

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 loadSrc and strip it from the URL, (b) save code to localStorage and update the URL hash, and (c) load code from localStorage by 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

  • tryFetchCodeFromSourceAndStripURL doesn’t await the provided handler. Callers currently pass an async handler (e.g. in codeworld.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 when tryFetch... resolves. Consider await 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.

Comment thread web/js/codeworld_shared.js Outdated
Comment thread web/js/codeworld.js Outdated
Comment thread web/js/run.js Outdated
Comment thread web/js/codeworld_shared.js Outdated
Comment thread web/js/codeworld_shared.js
Comment thread web/js/run.js Outdated
Comment thread web/js/run.js
Copy link
Copy Markdown

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

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

Comment thread web/js/codeworld_shared.js Outdated
Comment thread web/js/codeworld.js Outdated
Comment thread web/js/run.js
@patritzenfeld patritzenfeld merged commit d6c0ac4 into fmidue:fmidue May 15, 2026
1 check passed
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.

3 participants