Skip to content

fix(codec): preserve sparse array slots in state previews - #1168

Open
shuaiyafei wants to merge 1 commit into
vuejs:mainfrom
shuaiyafei:fix/sparse-array-state-preview
Open

shuaiyafei wants to merge 1 commit into
vuejs:mainfrom
shuaiyafei:fix/sparse-array-state-preview

Conversation

@shuaiyafei

Copy link
Copy Markdown
Contributor

Summary

Materialize array preview entries with Array.from so sparse slots are represented as explicit encoded undefined values.

Previously, slice(...).map(...) retained holes in the preview array. A JSON transport then converted those holes to null, which is not a ValueEntry and cannot be read as preview.key / preview.value by the state inspector.

For example:

const value: unknown[] = []
value.length = 3
value[1] = 'visible'

JSON.parse(JSON.stringify(encodeValue(value))).preview
// Previously: [null, { key: '1', value: ... }, null]

The encoder now returns a dense preview with the original indices, without filling or mutating the inspected source array.

Regression Coverage

  • Mixed sparse slots and values survive a JSON round trip as valid preview entries.
  • An offset/limited preview retains the correct original array indices.
  • The inspected array keeps its original holes.

Both regression tests failed before the encoder change and pass with the fix.

Validation

  • pnpm lint
  • pnpm test: 407 tests passed across 67 files
  • pnpm typecheck
  • pnpm build

@netlify

netlify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vue-devtools-docs canceled.

Name Link
🔨 Latest commit 4179e94
🔍 Latest deploy log https://app.netlify.com/projects/vue-devtools-docs/deploys/6ad2d93fbb8fe7eec5588a4a

@pkg-pr-new

pkg-pr-new Bot commented Oct 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vue/devtools-agent@1168
npm i https://pkg.pr.new/@vue/devtools-api@1168
npm i https://pkg.pr.new/@vue/devtools-kit@1168
npm i https://pkg.pr.new/vite-plugin-vue-devtools@1168

commit: 4179e94

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