Skip to content

fix(AppShell): stop expression-mode script params reverting to simple mode - #2171

Open
alexwarren wants to merge 1 commit into
mainfrom
claude/epic-chandrasekhar-96342d
Open

fix(AppShell): stop expression-mode script params reverting to simple mode#2171
alexwarren wants to merge 1 commit into
mainfrom
claude/epic-chandrasekhar-96342d

Conversation

@alexwarren

Copy link
Copy Markdown
Contributor

Summary

  • isSimpleValue() in ScriptEditor.svelte classified any script-parameter value as a "simple" quoted literal whenever it merely started and ended with ", so a compound expression like "It weighs " + object.weight + " grams." (a Print message set to expression mode) was misdetected as simple.
  • Since every mutate()-triggering edit anywhere in the script tree calls refresh(), which unconditionally clears expressionOverrides, the mode dropdown re-derives "simple" from this flawed check on the very next render — silently flipping the field back to "message" mode and mangling the displayed text via toSimpleDisplay()'s slice(1, -1) (which assumes the first/last characters are the literal's own quotes).
  • The underlying saved script text was never actually corrupted by this — GetScriptCode/raw XML round-tripped the real expression the whole time — but the display bug made it look like the typed expression, and the save itself, had silently failed. Confirmed via Playwright that autosave does complete ("Saved" chip) even while this bug was live; only the visual state was wrong.
  • Fix: require the entire value to be a single valid string literal (an opening ", only non-quote/escaped-quote characters, then a closing ") rather than just checking the first/last characters.
  • Also affects the "flag name"/other quoted-string params of expressionField's template controls (e.g. "object has flag"), and any other textbox/dropdown/file-style script parameter — all route through the same shared isSimpleValue(). The objects/boolean/number cases already use stricter, unaffected checks.

Test plan

  • npm run check (svelte-check) — clean
  • npm run lint (eslint) — clean
  • Added tests/e2e/verify-appshell-print-expression-mode.mjs, verified it fails against the pre-fix code and passes against the fix
  • node tests/e2e/find-affected-tests.mjs flagged 18 scripts touching ScriptEditor.svelte; ran all 18 locally against the dev server — all pass

🤖 Generated with Claude Code

… mode

isSimpleValue()'s default case classified any value that merely started
and ended with a `"` as a simple quoted-string literal, so a compound
expression like `"a" + b + "c"` (e.g. Print's message field holding
`"It weighs " + object.weight + " grams."`) was misdetected as simple.
Any mutate()-triggering edit anywhere in the script tree calls refresh(),
which unconditionally clears expressionOverrides, so the mode dropdown
then re-derived "simple" from this flawed check and silently flipped
back to message mode, mangling the display via toSimpleDisplay's
slice(1, -1). The underlying saved script text was never actually
corrupted - only the display was - but this made it look like the typed
expression had been lost. Tightened the check to require the whole
value be a single valid string literal (no unescaped quotes in the
middle).
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