Skip to content

Conversation

@takashi-kasajima
Copy link
Contributor

@takashi-kasajima takashi-kasajima commented Sep 20, 2025

Closes #32000

What I did

This PR fixes a bug in the functionality that adds new values to array controls. The feature wasn't working since the key was not passed while it requires an index to be in there.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Run in the code directory by yarn storybook:ui
  2. Open Storybook in your browser
  3. Access the story ADDONS/docs/blocks/Controls/Object/Array
  4. Confirm it adds a new value by clicking [Save] or pressing the enter key
image

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Bug Fixes

    • Adding a value to a JSON array in the editor now automatically assigns the next index, ensuring consistent insertion and accurate change tracking. This prevents mismatched keys and improves reliability when updating arrays.
  • Refactor

    • Simplified the add-value flow for JSON arrays to compute the index internally, resulting in more predictable behavior without requiring manual key input.

@nx-cloud
Copy link

nx-cloud bot commented Sep 20, 2025

View your CI Pipeline Execution ↗ for commit 50afef0

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 46s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-24 12:25:33 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 24, 2025

Walkthrough

The JsonArray class in JsonNodes.tsx changed the handleAddValueAdd method signature to accept only { newValue } instead of { key, newValue }. The method now computes key internally as data.length. The internal flow uses the derived key for beforeAddAction, updating the array data at the computed index, and emitting delta updates. No other control-flow changes are indicated.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant C as JsonArray component
  participant H as beforeAddAction hook
  participant S as State/Data
  participant E as Delta/Change Emitter

  U->>C: Click "+" and Save new value
  Note over C: New flow: no external key provided
  C->>C: key = data.length
  C->>H: beforeAddAction(key, newValue)
  H-->>C: ok / continue
  C->>S: Insert newValue at index=key
  C->>E: Emit delta with key and newValue
  E-->>U: UI reflects updated array
Loading
sequenceDiagram
  autonumber
  participant Old as Old Flow (pre-change)
  participant New as New Flow (post-change)

  rect rgb(240,240,255)
  note right of Old: External key passed in params
  Old->>Old: handleAddValueAdd({ key, newValue })
  end

  rect rgb(240,255,240)
  note right of New: Key derived from data length
  New->>New: handleAddValueAdd({ newValue })
  New->>New: key = data.length
  end
Loading

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Controls: Fix adding new values to arrays" is concise and clearly describes the primary change — fixing the array-control add/save behavior — and it matches the changeset intent targeting array value addition in controls. It avoids noise and is specific enough for teammates scanning history.
Linked Issues Check ✅ Passed The change updates JsonArray.handleAddValueAdd to compute the missing index (key = data.length) and use it when updating data and emitting delta events, which directly addresses linked issue #32000 where new array items were not persisted via the UI; this meets the coding objective to ensure array controls save new values. The PR implements the necessary code fix, though it does not add automated tests to verify the regression is prevented.
Out of Scope Changes Check ✅ Passed The provided summary shows a single targeted edit in code/addons/docs/src/blocks/controls/react-editable-json-tree/JsonNodes.tsx to derive the array index when adding values, and there are no other unrelated file changes in the diff, so the change is in scope for the linked issue.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@ndelangen ndelangen changed the title Docs: Fix the functionality for adding new values to controls for arrays Controls: Fix adding new values to arrays Sep 24, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
code/addons/docs/src/blocks/controls/react-editable-json-tree/JsonNodes.tsx (2)

263-266: Minor: use push() for appending

Semantically clearer for appending to arrays.

-        // Update data
-        data[key] = newValue;
+        // Update data
+        data.push(newValue);

255-255: Tighten param typing

Narrow the destructured param type for clarity.

-  handleAddValueAdd({ newValue }: any) {
+  handleAddValueAdd({ newValue }: { newValue: any }) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68140f7 and 50afef0.

📒 Files selected for processing (1)
  • code/addons/docs/src/blocks/controls/react-editable-json-tree/JsonNodes.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: normal
  • GitHub Check: Danger JS
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (1)
code/addons/docs/src/blocks/controls/react-editable-json-tree/JsonNodes.tsx (1)

255-282: Good fix — derive array index internally; callers don't pass a key

JsonAddValue only includes key when onlyValue is false; the array render sets onlyValue={true} so it never passes a key, while the object render uses the separate handler that accepts {key, newValue}.

@ndelangen ndelangen merged commit 2e13905 into storybookjs:next Sep 25, 2025
56 of 61 checks passed
@github-actions github-actions bot mentioned this pull request Sep 25, 2025
16 tasks
@ndelangen ndelangen added the needs qa Indicates that this needs manual QA during the upcoming minor/major release label Sep 29, 2025
@storybook-app-bot
Copy link

Package Benchmarks

Commit: 50afef0, ran on 29 September 2025 at 10:57:11 UTC

The following packages have significant changes to their size or dependencies:

@storybook/addon-docs

Before After Difference
Dependency count 18 18 0
Self size 2.07 MB 2.06 MB 🎉 -11 KB 🎉
Dependency size 9.44 MB 9.43 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-vitest

Before After Difference
Dependency count 6 6 0
Self size 501 KB 491 KB 🎉 -11 KB 🎉
Dependency size 1.53 MB 1.53 MB 0 B
Bundle Size Analyzer Link Link

@storybook/builder-vite

Before After Difference
Dependency count 11 11 0
Self size 330 KB 319 KB 🎉 -10 KB 🎉
Dependency size 1.30 MB 1.30 MB 0 B
Bundle Size Analyzer Link Link

@storybook/html-vite

Before After Difference
Dependency count 14 14 0
Self size 23 KB 23 KB 🚨 +18 B 🚨
Dependency size 1.67 MB 1.66 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 531 531 0
Self size 950 KB 939 KB 🎉 -11 KB 🎉
Dependency size 58.43 MB 58.41 MB 🎉 -21 KB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs-vite

Before After Difference
Dependency count 124 124 0
Self size 4.10 MB 4.01 MB 🎉 -81 KB 🎉
Dependency size 21.62 MB 21.59 MB 🎉 -31 KB 🎉
Bundle Size Analyzer Link Link

@storybook/preact-vite

Before After Difference
Dependency count 14 14 0
Self size 14 KB 14 KB 🎉 -18 B 🎉
Dependency size 1.65 MB 1.64 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-native-web-vite

Before After Difference
Dependency count 157 157 0
Self size 31 KB 31 KB 🎉 -24 B 🎉
Dependency size 23.01 MB 22.97 MB 🎉 -31 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-vite

Before After Difference
Dependency count 114 114 0
Self size 37 KB 37 KB 0 B
Dependency size 19.56 MB 19.53 MB 🎉 -31 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-webpack5

Before After Difference
Dependency count 272 272 0
Self size 25 KB 25 KB 🚨 +18 B 🚨
Dependency size 43.35 MB 43.33 MB 🎉 -21 KB 🎉
Bundle Size Analyzer Link Link

@storybook/svelte-vite

Before After Difference
Dependency count 19 19 0
Self size 59 KB 59 KB 🎉 -52 B 🎉
Dependency size 26.79 MB 26.78 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/sveltekit

Before After Difference
Dependency count 20 20 0
Self size 58 KB 48 KB 🎉 -11 KB 🎉
Dependency size 26.85 MB 26.84 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/vue3-vite

Before After Difference
Dependency count 109 109 0
Self size 38 KB 38 KB 0 B
Dependency size 43.78 MB 43.77 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/web-components-vite

Before After Difference
Dependency count 15 15 0
Self size 20 KB 20 KB 🎉 -18 B 🎉
Dependency size 1.70 MB 1.68 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 187 187 0
Self size 905 KB 890 KB 🎉 -14 KB 🎉
Dependency size 79.76 MB 79.76 MB 🎉 -2 KB 🎉
Bundle Size Analyzer Link Link

@storybook/react-dom-shim

Before After Difference
Dependency count 0 0 0
Self size 22 KB 12 KB 🎉 -10 KB 🎉
Dependency size 785 B 785 B 0 B
Bundle Size Analyzer Link Link

@storybook/preset-create-react-app

Before After Difference
Dependency count 68 68 0
Self size 36 KB 26 KB 🎉 -10 KB 🎉
Dependency size 5.97 MB 5.97 MB 0 B
Bundle Size Analyzer Link Link

@storybook/react

Before After Difference
Dependency count 2 2 0
Self size 894 KB 884 KB 🎉 -10 KB 🎉
Dependency size 28 KB 18 KB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@yannbf yannbf assigned yannbf and unassigned ndelangen Oct 2, 2025
@yannbf yannbf removed the needs qa Indicates that this needs manual QA during the upcoming minor/major release label Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Control with array doesn't save new value

4 participants