-
Notifications
You must be signed in to change notification settings - Fork 64
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
fix failed render during page navigation #317
fix failed render during page navigation #317
Conversation
@JoshuaRotimi is attempting to deploy a commit to the Cloudinary DevX Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -125,6 +125,15 @@ const CldUploadWidget = ({ | |||
}); | |||
} | |||
|
|||
useEffect(() => { | |||
handleOnLoad(); |
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.
@JoshuaRotimi we actually don't need this here - Next.js works a little bit differently than vanilla React in that it has the Script component, so this function gets invoked as soon as the script is ready that handles initialization
that means that this function could actually possibly create an error (might be happening on the other work you're doing) in that it could potentially try to initialize without the Script being ready
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.
Oh alright. After trying multiple things, I found out that calling the handleOnLoad
function in the useEffect fixes the rendering issue when you navigate between pages with the CldVideoPlayer
component. I would further check to see if that is what causes the error on the examples repo that you mentioned.
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.
i tried commenting out that line and it seemed to work without it, just with the <Script tag natively reloading between the pages - where are you seeing an issue?
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.
Oh sorry. Not on this one. The comment should have been on the other component CldVideoPlayer
component not the CldUploadWidget
. You are correct. It should work without that on the CldUploadWidget
.
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.
got it okay - i would expect the same for the video player though, ill test locally too
@@ -161,6 +161,16 @@ const CldVideoPlayer = (props: CldVideoPlayerProps) => { | |||
} | |||
} | |||
|
|||
useEffect(() => { | |||
handleOnLoad(); |
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.
similar thing going on here, this shouldn't happen here
nice work @JoshuaRotimi it seems to clear the issues we were seeing!! just a few small tweaks needed |
@colbyfayock I'm currently having some issues calling the |
can you clarify if it's a Type issue or if it's an issue with the instance not being available at the time of unmounting? just in case there's a race condition there if it's a Type issue, let's at a |
Oh yes it is a type issue, |
i need to test it again i just found out however that there's another
https://nextjs.org/docs/pages/building-your-application/optimizing/scripts#executing-additional-code i would imagine that's actually what we would want, correct? it may not make the initial load more reliable, but it should make the page navigation more reliable and prevent us from having to include the additional initialization inside useEffect h/t: https://twitter.com/stordahldotdev/status/1719098207651905820?s=61&t=ya091PlFoeyCWxWs2FVkIQ |
Alright. You can pull the latest changes and test it again then let me know if it works. I will check out the |
It's better than it was before but it's still having issues loading completely reliably between page loads Notice on the 3rd and 4th navigation as well as some others we're missing a video. Let's see how onReady works here, it might resolve the issue |
@JoshuaRotimi any luck? |
the onReady callback only runs once, so only the first component is loaded properly so I'm still unable to figure out the best solution so far. any ideas? @colbyfayock |
i see what you mean. i dont have any quick ideas ill need to spend more time thinking about this i think there's enough value to move forward with this now though without waiting to help address some issues for people can you remove the examples at the bottom of: docs/pages/cldvideoplayer/basic-usage.mdx then i can merge it in and perhaps if you'er still interested in looking into this we can do it in another ticket, otherwise i can take over thanks @JoshuaRotimi |
Alright done. |
thanks @JoshuaRotimi - awesome job with this!! merging as a minor release update since its a bit more than a simple fix |
🎉 This PR is included in version 5.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [5.4.0](cloudinary-community/next-cloudinary@v5.3.0...v5.4.0) (2023-11-09) ### Features * dispose of upload widget and video player instance on unmount ([#317](cloudinary-community/next-cloudinary#317)) ([a313b7a](cloudinary-community/next-cloudinary@a313b7a)), closes [#279](cloudinary-community/next-cloudinary#279) [#279](cloudinary-community/next-cloudinary#279)
Description
This PR fixes the issue #279 where some players fail to load when rendering multiple
CldVideoPlayer
on one page.CldVideoPlayer
component fails to render properly after navigating between pagesCldUploadWidget
component unmountIssue Ticket Number
#279
Fixes #<ISSUE_NUMBER>
Type of change
Checklist