Skip to content
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

OnLoadingComplete not working when passing function, but works when console log #29363

Closed
levelingup opened this issue Sep 24, 2021 · 5 comments · Fixed by #29367
Closed

OnLoadingComplete not working when passing function, but works when console log #29363

levelingup opened this issue Sep 24, 2021 · 5 comments · Fixed by #29367
Assignees

Comments

@levelingup
Copy link

What version of Next.js are you using?

11.1.2

What version of Node.js are you using?

10.20.1

What browser are you using?

chrome

What operating system are you using?

codesandbox

How are you deploying your application?

codesandbox

Describe the Bug

I'm trying to get the naturalWidth and naturalHeight from onLoadingComplete props: https://nextjs.org/docs/api-reference/next/image#onloadingcomplete but its not working? Perhaps I'm doing it wrong?

I have a codesandbox, lines 62, 63: https://codesandbox.io/s/proud-rain-d51sv?file=/pages/index.js

When you upload an image, console log only works, but it doesn't work when I'm trying to pass handleImageLoad function listed in the sandbox.

Expected Behavior

Trying to get naturalWidth and naturalHeight

To Reproduce

https://codesandbox.io/s/proud-rain-d51sv?file=/pages/index.js lines 62, 63

@levelingup levelingup added the bug Issue was opened via the bug report template. label Sep 24, 2021
@ijjk
Copy link
Member

ijjk commented Sep 24, 2021

Hi, it looks like we don't currently call onLoadingComplete for data URLs and that's why you aren't seeing the function called. Note: the console.log is showing since it isn't wrapped in a function so will be executed every time that component is rendered

@styfle
Copy link
Member

styfle commented Sep 24, 2021

The issue is that react-images-uploading returns a Data URI and the Image component assumes it was a blur placeholder so it never calls

if (!img.src.startsWith('data:')) {

This should fix it: #29367

@styfle styfle added kind: bug and removed bug Issue was opened via the bug report template. labels Sep 24, 2021
@styfle styfle self-assigned this Sep 24, 2021
@levelingup
Copy link
Author

Thanks @ijjk and @styfle so I was able to convert the data uri into blob, which did work. So for future next.js version, I should be able to get onLoadingComplete with data uri?

@kodiakhq kodiakhq bot closed this as completed in #29367 Sep 26, 2021
kodiakhq bot pushed a commit that referenced this issue Sep 26, 2021
Fixes #29363 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
@styfle
Copy link
Member

styfle commented Sep 27, 2021

@levelingup The fix for Data URI is available in v11.1.3-canary.33

You can try it out with yarn add next@canary, thanks!

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
…#29367)

Fixes vercel#29363 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants