Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"build:storybook": "storybook build",
"build:docs": "NODE_OPTIONS=--openssl-legacy-provider script/build-docs",
"build:docs:preview": "NODE_OPTIONS=--openssl-legacy-provider script/build-docs preview",
"build:components.json": "node script/components-json/build.ts",
"build:hooks.json": "node script/hooks-json/build.ts",
"build:components.json": "tsx script/components-json/build.ts",
"build:hooks.json": "tsx script/hooks-json/build.ts",
"build:precompile-color-schemes": "tsx script/precompile-color-schemes.ts",
"lint:npm": "publint --types",
"storybook": "storybook",
Expand Down
10 changes: 6 additions & 4 deletions packages/react/script/components-json/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import prettier from '@prettier/sync'
import chalk from 'chalk'
import type {LintError} from 'markdownlint'
import {lint as mdLint} from 'markdownlint/sync'
import componentSchema from './component.schema.json' with {type: 'json'}
import outputSchema from './output.schema.json' with {type: 'json'}
import componentSchema from './component.schema.json'
import outputSchema from './output.schema.json'

const args = parseArgs({
options: {
Expand Down Expand Up @@ -160,6 +160,7 @@ const components = docsFiles.map(docsFilepath => {
if (id.endsWith('--default')) {
return {
id,
code: defaultStoryCode,
}
}
const storyName = getStoryName(id)
Expand All @@ -171,18 +172,19 @@ const components = docsFiles.map(docsFilepath => {
)
}

return {id}
return {id, code}
})

// Replace the stories array with the new array that includes source code
docs.stories = stories

// Add default story to the beginning of the array
if (defaultStoryCode) {
const hasDefaultStory = docs.stories.find(story => story.id === defaultStoryId)
const hasDefaultStory = docs.stories.find(story => story.code === defaultStoryCode)
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

This logic for checking if a default story already exists is incorrect. It's comparing story.code === defaultStoryCode (checking if the code content matches), but it should be comparing story.id === defaultStoryId (checking if the story ID matches).

This could lead to duplicate stories with the same ID if the code content doesn't match exactly, or it could incorrectly skip adding the default story if a different story happens to have identical code.

Suggested fix:

const hasDefaultStory = docs.stories.find(story => story.id === defaultStoryId)
Suggested change
const hasDefaultStory = docs.stories.find(story => story.code === defaultStoryCode)
const hasDefaultStory = docs.stories.find(story => story.id === defaultStoryId)

Copilot uses AI. Check for mistakes.
if (!hasDefaultStory) {
docs.stories.unshift({
id: defaultStoryId,
code: defaultStoryCode,
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react/script/hooks-json/build.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import glob from 'fast-glob'
import fs from 'fs'
import keyBy from 'lodash.keyby'
import hookSchema from '../hooks-json/hook.schema.json' with {type: 'json'}
import outputSchema from './output.schema.json' with {type: 'json'}
import hookSchema from '../hooks-json/hook.schema.json'
import outputSchema from './output.schema.json'
import Ajv from 'ajv'

// Only includes fields we use in this script
Expand Down
Loading