refactor(VideoInfo): return a WatchNextContinuation instead of mutating state - #1239
Open
MFA-G wants to merge 1 commit into
Open
refactor(VideoInfo): return a WatchNextContinuation instead of mutating state#1239MFA-G wants to merge 1 commit into
MFA-G wants to merge 1 commit into
Conversation
…ng state `VideoInfo#getWatchNextContinuation()` overwrote `watch_next_feed` and the private continuation token on the existing instance and returned `this`. That in-place mutation is awkward to work with in reactive frameworks (e.g. Vue), since the same object identity is reused while its contents change underneath. Add a `WatchNextContinuation` class mirroring `CommentsContinuation`: it holds the parsed `contents`, exposes `has_continuation`, and returns a brand new instance from `getContinuation()`. The `ContinuationItem` is filtered out of `contents` instead of being popped off the array, so the feed items are never mixed with the continuation marker. BREAKING CHANGE: `VideoInfo#getWatchNextContinuation()` now resolves to a `WatchNextContinuation` instead of the mutated `VideoInfo`. Read the new items from `.contents` and keep calling `.getContinuation()` on the returned object to page further. Closes LuanRT#1237
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.
Fixes #1237
What
VideoInfo#getWatchNextContinuation()mutated the instance in place: it overwrotewatch_next_feed, reassigned the private#watch_next_continuation, and returnedthis. As noted in the issue, that pattern doesn't play well with reactive frameworks (Vue and friends) because the object identity stays the same while its contents change underneath.This adds a
WatchNextContinuationclass modelled directly on the existingCommentsContinuation/CommentThread#getContinuation()pattern referenced in the issue:VideoInfo#getWatchNextContinuation()now just builds one from the response and returns it;VideoInfoitself is left untouched.Two small behavioural notes:
ContinuationItemis filtered out ofcontentsrather thanpop()ed off after the fact, so feed items are never mixed with the continuation marker (the old code also relied on it being the last element).InnertubeErroris thrown whenAppendContinuationItemsActionis missing, same as before.I deliberately left
VideoInfo's constructor,watch_next_feed, andwn_has_continuationalone — the initial feed still comes from the watch page as it always did, so nothing changes for the first page.Breaking change
getWatchNextContinuation()used to resolve to the (mutated)VideoInfo. It now resolves to aWatchNextContinuation:Note that
YTShorts.ShortFormVideoInfo#getWatchNextContinuation()has the same mutation pattern but a different response shape (reel_watch_sequence/ContinuationCommand), so I left it out of this PR to keep the change focused. Happy to follow up on it if you'd like it aligned too.Testing
npx tsc --noEmit -p tsconfig.json— cleannpx eslint src/— cleannpm run build:esmandnpm run build:parser-map— clean (the new class is exported fromsrc/parser/misc.tsby the generator, as withCommentsContinuation)appendContinuationItemsActionpayload to verify behaviour end to end:The
tests/main.test.tssuite hits the live API and the onlygetWatchNextContinuationcase there is the Shorts one, which is unaffected.