-
Notifications
You must be signed in to change notification settings - Fork 344
fix(preview): add preview sdk load check #4391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds a guard to ContentPreview that tracks external preview library availability via a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/elements/content-preview/ContentPreview.js(3 hunks)src/elements/content-preview/__tests__/ContentPreview.test.js(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/elements/content-preview/__tests__/ContentPreview.test.js (1)
src/elements/content-preview/ContentPreview.js (3)
props(291-301)props(322-322)props(377-377)
src/elements/content-preview/ContentPreview.js (6)
src/elements/content-preview/__tests__/ContentPreview.test.js (1)
file(18-18)src/elements/content-sidebar/__tests__/ActivitySidebar.rtl.test.js (1)
file(74-79)src/elements/content-sidebar/__tests__/ActivitySidebar.test.js (1)
file(49-54)src/api/__tests__/Feed.test.js (1)
file(349-364)src/elements/content-sidebar/__tests__/Sidebar.test.js (1)
file(28-33)src/api/File.js (1)
file(229-229)
🪛 Biome (2.1.2)
src/elements/content-preview/ContentPreview.js
[error] 231-231: return types can only be used in TypeScript files
remove this type annotation
(parse)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Summary
🔇 Additional comments (6)
src/elements/content-preview/ContentPreview.js (3)
231-232: LGTM!The new
previewLibraryLoadedproperty correctly tracks the preview library's load state. The static analysis hint about TypeScript syntax is a false positive—this is valid Flow syntax (the file has@flowdirective on line 2).
457-462: LGTM! Good fix for the race condition.The guard correctly detects when the preview library becomes available after the file was already set, ensuring the preview load is retried. The
!this.previewcheck appropriately prevents re-triggering if a preview instance already exists.The side effect (setting
previewLibraryLoaded = true) in ashould*method is slightly unconventional, but the comment clearly explains the intent and it's a pragmatic solution for synchronizing state.
820-822: LGTM!Updating
previewLibraryLoadedbefore the guard ensures the instance property stays synchronized with the actual library state. This allowsshouldLoadPreviewto correctly detect when the library becomes available on subsequent updates ifloadPreviewreturns early here.src/elements/content-preview/__tests__/ContentPreview.test.js (3)
178-185: LGTM!Good test coverage for the new guard logic. It correctly verifies both the return value and the side effect of setting
previewLibraryLoadedto true.
505-514: LGTM!Good test for the early return behavior. Using
getFileIdas a proxy to verify execution stopped early is a reasonable approach since it's called after the guard check.
525-533: LGTM!Good test coverage for the token validation in the guard. Correctly verifies that
loadPreviewreturns early when the token is not set.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Merge Queue Status✅ The pull request has been merged at 59cbe2a This pull request spent 4 seconds in the queue, with no time running CI. Required conditions to merge
|
This PR fixes an edge case where if the file info for the preview is loaded but the preview sdk is not, then the ContentPreview gets stuck in a perpetual loading state. This can happen on clients with increased network latency. When the function shouldLoadPreview executes on componentDidUpdate it checks to see whether or not the file is loaded and if it's new relative to the preview. If it is then loadPreview is set to true and which leads ContentPreview to attempt to load the preview. If the preview sdk is not loaded then loadPreview will return without actually calling the preview sdk and showing the preview. This leads to the perpetual loading state because shouldLoadPreview, when it's called again in componentDidUpdate, will always return false because the file will no longer be considered new relative to the component's state.
To fix this, I added a new field to the ContentPreview which keeps track of the preview sdk loaded state. This is the basis of a new conditional in shouldLoadPreview PR Ref that will return true and ultimately cause the preview to load if the preview sdk wasn't previously loaded but currently is.
Before
After
Before Screenshot: The logpoint pointed to by the red arrow shows where loadPreview gets called but the preview sdk isn't loaded.
After Screenshot: The arrow on the top points to the logpoint message that gets logged in loadPreview if the preview is trying to load but the sdk isn't ready. The arrow on the bottom points to the logpoint messages that get logged when shouldLoadPreview returns true because the preview sdk wasn't ready before but is now and then when the preview sdk actually gets called in the loadPreview function.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.