Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Editor loads scripts at wrong time #1867

Conversation

catloversg
Copy link
Contributor

Test scripts:
test.ts

import { multiply } from "./lib";

export async function main(ns: NS) {
  ns.print(`multiply: ${multiply(2, 3)}`);
}

lib.ts

export const multiply = (a: number, b: number) => a * b;

How to reproduce this bug:

  • Load a clean save file.
  • Save test scripts. Reload the page.
  • nano test.ts.
  • Switch to the terminal tab, then switch back to the editor tab.

Capture

loadAllServerScripts is called in parseCode. There are 2 problems:

  • loadAllServerScripts is called every time the player edits their code. This means that it's called after every keystroke.
  • Even in this case, calling it in parseCode is still too late. It needs to be called much earlier. The start of onMount is a proper place. I also call it in onTabClick. It may be useful if something else (via NS APIs or RFA) changes (add/edit/delete) scripts. For example, if an external editor pushes a script via RFA, we will load that new script when the player switches tabs. Technically, doing that in debouncedCodeParsing may be better, but I think it's overkill.

@catloversg catloversg changed the title BUGFIX: Editor load scripts at wrong time BUGFIX: Editor loads scripts at wrong time Dec 22, 2024
@catloversg catloversg marked this pull request as draft December 25, 2024 05:45
@catloversg
Copy link
Contributor Author

Superseded by #1893.

@catloversg catloversg closed this Jan 5, 2025
@catloversg catloversg deleted the pull-request/bugfix/editor-load-scripts-at-wrong-time branch January 8, 2025 10:17
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.

1 participant