Skip to content

Token reorder silently discarded for numeric names without leading zeros in code editor #3874

@UdayHyma

Description

@UdayHyma

Describe the bug
In the built-in JSON code editor, a token named 1000 cannot be reordered below token 0950. After editing the JSON to move it, fixing commas, and clicking save, the change is silently discarded — the push icon stays deactivated and inspecting the code shows the original order. Other tokens in the same group (all with leading zeros: 0000, 0050, 0100, etc.) can be reordered freely.
To Reproduce

Have a token group (e.g. color.base_palette) with tokens named: 1000, 0000, 0050, 0100, 0150, ..., 0900, 0950
Switch to the JSON code editor view
Move the "1000" entry below "0950" in the JSON
Fix any trailing commas
Click "Save"
1000 snaps back to the top of the group — the edit is silently lost

Expected behavior
Token 1000 should stay in the position where the user placed it.
Screenshots or Screencasts
Screenshot from reporter showing the token list with 1000 stuck at the top of color > base_palette, above all 0xxx tokens.

Image

JSON (optional)
json{
"color": {
"base_palette": {
"0000": { "value": "#000000", "type": "color" },
"0050": { "value": "#0a0a0a", "type": "color" },
"0950": { "value": "#f2f2f2", "type": "color" },
"1000": { "value": "#ffffff", "type": "color" }
}
}
}
After saving, 1000 will always appear first regardless of placement.
Root cause (from code investigation)
JavaScript spec: object keys that are valid array indices (non-negative integers without leading zeros) are enumerated numerically before all string keys. "1000" is a valid integer — "0950" has a leading zero so it's treated as a string.
When saving: setJSONData (src/app/store/models/tokenState.tsx, line 249) → parseTokenValues (src/utils/parseTokenValues.ts, line 29) → convertToTokenArray (src/utils/convertTokens.tsx, line 133) uses Object.entries() which reorders "1000" to the front.
Reproduced in Node.js:
javascriptconst obj = JSON.parse('{"0000":{}, "0050":{}, "0950":{}, "1000":{}}');
console.log(Object.keys(obj));
// → ["1000", "0000", "0050", "0950"]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

Status

📥 Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions