8000 onImageLoaded called with undefined with odd conditions · Issue #121 · dominictobias/react-image-crop · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
onImageLoaded called with undefined with odd conditions #121
Closed
@samsch

Description

@samsch

onImageLoaded is first called with undefined when the ReactCrop component is initially rendered with a src value, seemingly when rebuilt with Webpack. It's fairly consistent in Firefox, only seems to happen sometimes in Chrome.

Test case here: https://codesandbox.io/s/lo9no1mkm.

  1. Turn OFF Preview On Edit in codesandbox.io settings.
  2. Open browser console
  3. Comment out or uncomment the final line (render('');) in index.js, and save (which rebuilds).
  4. Select image with file input

The codesandbox.io output will show the React POV with a cross origin error due to the top level event being an image input event, but in the console you can see either "image is undefined` in Firefox or Chrome complain about accessing properties of undefined.

I'm not entirely certain about the possible cases. In a project I am working on which uses webpack-dev-server (not CRA), it always calls onImageLoaded with undefined in Firefox unless rendered with a blank value first.

I don't have any particularly good guesses about the cause, but I am wondering if perhaps there is an odd interaction happening which involves webpack-dev-server.

-EDIT-
There is a very simple workaround for this, which is to simply add if (!image) { return; } to the top of your onImageLoaded handler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0