refactor(frontend): split GeneratePodcastDialog and fix token-count races - #1067
Merged
Conversation
…aces Extract ContentSelectionPanel and shared selection helpers into their own modules, deduplicate the sources/notes context-config reduction into selectionsToContextConfigs, delete the obsolete translation cache (plain react-i18next t() now), debounce the token/char counter with a stale-response guard, and close the dialog when the episode refetch resolves instead of after a fixed 500ms timer.
Contributor
There was a problem hiding this comment.
No issues found across 4 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
You’re at about 90% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
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.
Summary
GeneratePodcastDialog.tsxhad grown to 983 lines and hid two real concurrency bugs. This PR splits the file and fixes the races. Structural moves are behavior-identical; the two behavior changes are called out below.Structural (behavior-identical)
ContentSelectionPanelextracted tofrontend/src/components/podcasts/ContentSelectionPanel.tsx. It now gets the query client viauseQueryClient()instead of a rawqueryClientprop, and the handler props are namedonNotebookToggle/onSourceModeChange/onNoteToggle.frontend/src/components/podcasts/generate-podcast-selection.ts(SourceMode,NotebookSelection,formatNumber,hasSelections,getSourceDefaultMode).sourcesConfig/notesConfigreduction deduplicated: the identical logic in the token-count effect andbuildContentFromSelectionsis now oneselectionsToContextConfigs(selections)helper.tr = {...}block referenced a Proxy-basedt()that no longer exists (translations are plain react-i18next now); the panel callst()directly.Behavior fixes
chatApi.buildContextserially per notebook on every selections change with no debounce and no cancellation — rapid checkbox toggling produced overlapping request storms with last-write-wins onsetTokenCount. Now debounced (400ms) with a generation-counter stale guard: a newer effect run invalidates any in-flight loop, so stale responses can neither accumulate into the totals nor overwrite fresher counts.handleSubmitclosed viasetTimeout(..., 500)"to ensure refetch completes" — a sleep racing a network call.useGeneratePodcast'sonSuccessalready awaitsrefetchQueries, andmutateAsynconly resolves afteronSuccesssettles, so the dialog now closes immediately afterawait mutateAsync(...)— deterministically after the refetch.Verification
Inside
frontend/:npm run lint— 0 errors (8 pre-existing warnings, none introduced)npm run test— 12 files, 85 tests passednpm run build— succeeds