Skip to content

Sync open pxt.json editor buffer when package config is updated - #11666

Open
Dmitriy Antipov (THEb0nny) wants to merge 1 commit into
microsoft:masterfrom
THEb0nny:fix/pxtjson-editor-sync
Open

Dmitriy Antipov (THEb0nny) wants to merge 1 commit into
microsoft:masterfrom
THEb0nny:fix/pxtjson-editor-sync

Conversation

@THEb0nny

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where pxt.json does not update when open in the editor (Monaco text editor or project settings) while project files or dependencies are added, renamed, or deleted.

Root Cause

When files or dependencies are added, renamed, or removed, updateConfigAsync updates pxt.json on disk and in cfgFile.content. However:

  1. If pxt.json is currently open in the Monaco text editor, Monaco's in-memory model (pkg:pxt.json) was not being updated.
  2. setContentAsync was called without force = true, so change listeners were not notified.
  3. Consequently, upon subsequent file switching or autosave debounce, saveCurrentSourceAsync read from the stale Monaco buffer and saved the old text back into pxt.json, undoing the file addition, rename, or deletion.

Changes

  1. webapp/src/package.ts (updateConfigAsync):
    • Reads the latest content from the active Monaco model if open (preserving any unsaved typing).
    • Synchronously updates Monaco's model buffer (pxtJsonModel.setValue(newContent)) with the new JSON config so the UI updates immediately and subsequent saves use the new content.
    • Passes force = true to setContentAsync to notify listeners of programmatic changes.
  2. webapp/src/pxtjson.tsx (pxtjson.Editor):
    • Registers setForceChangeCallback so the visual settings editor also refreshes automatically when the config changes externally.

Videos

Before (bug):
https://github.com/user-attachments/assets/e27ffa94-9854-469a-b53b-908811e7d979

After (fixed):
https://github.com/user-attachments/assets/04db5a57-4231-4697-b1c6-0b52f53ead5f

@THEb0nny

Copy link
Copy Markdown
Contributor Author

The bug was discovered while working with the new filelist rename function.
#11664
It's not related to the pxt-ev3 target or that PR. You can check it on a different target.

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