Fix potential raceCondition in SET_CONFIG hook#35401
Conversation
|
📝 WalkthroughWalkthroughThe ChangesSET_CONFIG Filters Update
Estimated code review effort: 1 (Trivial) | ~3 minutes Related Issues: Not specified in provided context. Related PRs: Not specified in provided context. Suggested labels: manager-api, bug Suggested reviewers: Not specified in provided context. 🐰 A tiny tweak inside the state, ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
code/core/src/manager-api/modules/stories.ts (1)
1252-1272: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winRead all dependent filter state inside the updater.
filtersnow comes from the functional updater, butincludedTagFilters,excludedTagFilters,includedStatusFilters,excludedStatusFilters, andtagPresetsare still captured fromstore.getState()before the asyncsetStateruns. If any of those change before the updater executes,STATIC_FILTER/TAGS_FILTER/STATUS_FILTERwill still be built from stale values. Move those reads into the updater argument too.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@code/core/src/manager-api/modules/stories.ts` around lines 1252 - 1272, The SET_CONFIG handler in stories.ts is still building STATIC_FILTER, TAGS_FILTER, and STATUS_FILTER from values read via store.getState() before the functional update runs, so those dependent filter values can go stale. Move the reads for includedTagFilters, excludedTagFilters, includedStatusFilters, excludedStatusFilters, and tagPresets inside the store.setState updater alongside filters, and compute the managed filter functions from that updater state so all filter values are derived from the same snapshot.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@code/core/src/manager-api/modules/stories.ts`:
- Around line 1252-1272: The SET_CONFIG handler in stories.ts is still building
STATIC_FILTER, TAGS_FILTER, and STATUS_FILTER from values read via
store.getState() before the functional update runs, so those dependent filter
values can go stale. Move the reads for includedTagFilters, excludedTagFilters,
includedStatusFilters, excludedStatusFilters, and tagPresets inside the
store.setState updater alongside filters, and compute the managed filter
functions from that updater state so all filter values are derived from the same
snapshot.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 57d055fb-fee8-4404-a4d3-5d204f234d61
📒 Files selected for processing (1)
code/core/src/manager-api/modules/stories.ts
What I did
Found while sniffing for a related issue, this is a potential race condition in setState if filters are updated between the call to getState and the asynchronous setState
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
none required
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsDeclare whether manual QA will be needed for this PR during the next release, through
qa:neededorqa:skipMake 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/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>Summary by CodeRabbit