Skip to content

fix(video360): reselect viewer when cached preload upgrades to playable - #1987

Open
zhirongwang wants to merge 3 commits into
box:masterfrom
zhirongwang:fix/video360-preload-upgrade
Open

zhirongwang wants to merge 3 commits into
box:masterfrom
zhirongwang:fix/video360-preload-upgrade

Conversation

@zhirongwang

@zhirongwang zhirongwang commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Opening a .360 video from a list where the file was preloaded showed a flat video player. After a page refresh, the same file opened in the draggable Video360 viewer.

Cause

Hosts can put a file into the preview cache before it is opened. That cache entry is fetched without video rep hints, so it has the jpg preload rep but no dash/mp4.

  1. loadFromCache picks a viewer from that entry. Video360Loader requires dash, so it can't load the file, and MediaLoader's preload fallback picks the flat Dash viewer with the jpg rep.
  2. loadFromServer returns file info with dash.
  3. tryUpgradeVideoPreloadToPlayable checked only whether the current viewer config (Dash) had a matching rep. It did, so the flat Dash viewer was reloaded in place. Viewer selection never ran again.

After a refresh the cache is empty, so the first viewer choice already sees dash and picks Video360.

Fix

Before upgrading in place, run loader.determineViewer on the server file with the same arguments loadViewer uses. If that picks a different viewer (for example Video360 instead of Dash), call loadViewer(), which tears down the preload viewer and builds the right one.

  • Non-360 videos that keep the same viewer still upgrade the Dash/MP4 preload viewer in place.
  • The existing Dash-to-MP4 switch still goes through loadViewer(), as before.
  • When the reselected viewer matches, its rep is always the playable dash/mp4, so the old expectedRep / canUpgradeInPlace check and its fallback are removed.
  • If no loader can play the refreshed file, call loadViewer() so it reports the account or unsupported-file error. Before, this threw a TypeError that surfaced as a generic refresh error.
  • No change to X-Rep-Hints or requests. Both viewers play the same dash rep, so this adds no conversions.

Testing

  • Unit tests: added cases for the Video360 reload (one with the real loaders), the in-place Dash upgrade, and the no-loader path, and updated the existing upgrade mocks. The real-loader and no-loader tests fail on the old code.
  • Manually, with a host that preloads on hover: hovering then opening *.360.mp4 from the list now shows the preload image, then the Video360 viewer. A plain .mp4 still upgrades in place.

Summary by CodeRabbit

  • Bug Fixes
    • Improved video preload upgrades: previews now update in place when the current viewer supports the playable video, and reload with the appropriate viewer when needed. This helps ensure videos display correctly when switching formats, including 360° video.

A video opened from a cached entry without dash/mp4 starts in the jpg preload
viewer, which MediaLoader picks as flat Dash. When file info returns dash, the
preload upgrade reloaded that Dash viewer in place, so .360 videos stayed flat
until a page refresh. Re-run viewer selection on the server file first and call
loadViewer() when it picks a different viewer, such as Video360.
@zhirongwang
zhirongwang requested a review from a team as a code owner November 29, 2026 04:48
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The preload upgrade path now checks which viewer handles the playable file. If no loader is available or the selected viewer differs from the preload viewer, it calls loadViewer(). Otherwise, it updates the current viewer’s file and representation, then loads it.

Changes

Video preload viewer selection

Layer / File(s) Summary
Viewer selection and preload upgrade
src/lib/Preview.js, src/lib/__tests__/Preview-test.js
tryUpgradeVideoPreloadToPlayable calls loadViewer() when no loader is available or viewer selection changes. Otherwise, it updates the existing viewer’s file and representation and calls load. Tests cover MP4, Dash, and Video360 selection, viewer replacement, and in-place upgrades.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Preview
  participant Loader
  participant CurrentViewer
  participant NewViewer
  Preview->>Loader: determine viewer for playable file
  alt No loader or selected viewer differs
    Preview->>NewViewer: loadViewer
  else Selected viewer matches current viewer
    Preview->>CurrentViewer: update file and representation
    Preview->>CurrentViewer: load
  end
Loading

Suggested reviewers: sanilsalvi, abhishek1128, jackiejou

Merge Risk: Minimal · up to 74c33

This change makes a preloaded video switch to the correct viewer, such as Video360, once server file info is available. Plain videos still upgrade in place. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: when a cached video preload upgrades to a playable representation, the viewer is reselected, which fixes the .360 video selecting the flat Dash viewer. The changeset m…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: when a cached video preload upgrades to a playable representation, the viewer is reselected, which fixes the .360 video selecting the flat Dash viewer. The changeset matches this, since Preview.js reruns viewer determination and reloads the viewer when the selected viewer changes, and the tests cover Video360 replacement. The fix:/video360 scope prefix is an accurate scope for the Video360 case.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.3)

src/lib/__tests__/Preview-test.js

ast-grep timed out on this file

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit watched the preload flow,
Then saw the chosen viewer show.
If viewers differ, a new one starts,
If they match, the current one restarts.
The tests hop through each path with care.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5de141de-af7a-48f7-8c82-7dfd7ad18b6f
Commits

Reviewing files that changed from the base of the PR and between 0143213 and 74c33d4.

Files selected for processing: 2

  • src/lib/Preview.js
  • src/lib/__tests__/Preview-test.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@zhirongwang
zhirongwang force-pushed the fix/video360-preload-upgrade branch from a0b7fd2 to 0143213 Compare November 29, 2026 05:28
Once the reselected viewer matches the current one, its rep is always the
playable dash/mp4, so the expectedRep check and its fallback are redundant.
If no loader can play the refreshed file, call loadViewer() so it raises the
account or unsupported-file error instead of a generic refresh error. Also
clarify the viewer reselection comment, rename the upgrade tests, and add a
test that uses the real loaders to pick Video360.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant