fix(export): prevent prop-sync effects from reverting user format change#874
Merged
Merged
Conversation
The format/records/sort sync effects in useCitationExporter widened their dep arrays to include derived machine state during the telemetry PR's exhaustive-deps cleanup. After a user-initiated SET_FORMAT, params.format changed, the effect re-ran, saw format (prop) !== params.format (machine), and dispatched the original prop value back — instantly reverting the chosen export format. - Narrow dep arrays back to props only on the three one-way sync effects - Match the eslint-disable-line precedent used by the mount-only effect - Add useCitationExporter regression test covering SET_FORMAT persistence and prop -> machine sync
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #874 +/- ##
========================================
+ Coverage 62.6% 62.7% +0.1%
========================================
Files 324 324
Lines 38203 38205 +2
Branches 1733 1741 +8
========================================
+ Hits 23903 23918 +15
+ Misses 14259 14247 -12
+ Partials 41 40 -1
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Risk summary: Low regression risk; change is localized to prop→state-machine sync behavior in the citation exporter hook, with targeted test coverage added.
Findings (priority order):
- medium:
useCitationExporter’s format prop-sync effect still requires anexhaustive-depssuppression; it can be rewritten to depend only on theformatprop (anddispatch) without reading derived machine state. (Location:src/components/CitationExporter/useCitationExporter.ts, format sync effect; confidence: high)
Purpose: Prevent the citation export “prop-sync” effects from undoing a user-driven format change (regression introduced by prior telemetry-related changes), while ensuring prop changes still synchronize into the XState FSM.
Changes:
- Make prop→machine sync effects one-way by removing derived machine values from effect dependency arrays (prevents re-firing after user dispatches).
- Add hook-level tests to verify user-initiated
SET_FORMATpersists and prop changes still sync.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/CitationExporter/useCitationExporter.ts | Adjusts prop→FSM synchronization effects to avoid reverting user-initiated format changes. |
| src/components/CitationExporter/useCitationExporter.test.tsx | Adds regression tests for format sync behavior between props and the FSM. |
Comment on lines
88
to
+92
| useEffect(() => { | ||
| if (format !== params.format) { | ||
| dispatch({ type: 'SET_FORMAT', payload: format }); | ||
| } | ||
| }, [format, params.format, dispatch]); | ||
| }, [format]); // eslint-disable-line react-hooks/exhaustive-deps |
shinyichen
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix small export bug introduced by the sentry telemetry PR