beekai-oss / react-simple-img

🌅 React lazy load images with IntersectionObserver API and Priority Hints
MIT License
989 stars 41 forks source link

Break when using Route #35

Closed aeciolevy closed 5 years ago

aeciolevy commented 5 years ago

Hi Bill,

I am having problem while using react-simple-img:

Uncaught TypeError: Cannot read property 'observer' of undefined
    at SimpleImg.componentDidMount (simpleImg.js:142)
    at commitLifeCycles (react-dom.development.js:15986)
    at commitAllLifeCycles (react-dom.development.js:17388)
    at HTMLUnknownElement.callCallback (react-dom.development.js:147)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
    at invokeGuardedCallback (react-dom.development.js:250)
    at commitRoot (react-dom.development.js:17549)
    at completeRoot (react-dom.development.js:19002)
    at performWorkOnRoot (react-dom.development.js:18924)
    at performWork (react-dom.development.js:18826)
    at performSyncWork (react-dom.development.js:18799)
    at interactiveUpdates$1 (react-dom.development.js:19109)
    at interactiveUpdates (react-dom.development.js:2328)
    at dispatchInteractiveEvent (react-dom.development.js:5134)

If I redirect from another page to the one that I am using simple-img throw this error.

bluebill1049 commented 5 years ago

Hi @aeciolevy ,

can you take a look what's in the window object after route change?

window.__REACT_SIMPLE_IMG__

aeciolevy commented 5 years ago

I printed out the Window but there is just the REDUX constants... nothing with REACT_SIMPLE_IMG...

bluebill1049 commented 5 years ago

oh i see you are using the provider, i will have to take a look on this issue, will get back to you.

bluebill1049 commented 5 years ago

what about try initSimpleImg(); without the provider for now?

bluebill1049 commented 5 years ago

you are using react-router 4?

aeciolevy commented 5 years ago

Hi Bill,

I have not tested with initSimpleImg(). I can test it today.

I am using react-router 4.

I tried to lazy load in a Modal, it also breaks.

bluebill1049 commented 5 years ago

thanks @aeciolevy i will test it out over the weekend 👍

bluebill1049 commented 5 years ago

Hi @aeciolevy ,

i have made a patch and fixed the issue. please upgrade 👍

here is a working version with react router

https://codesandbox.io/s/z322vzlv83

cheers bill ❤️

aeciolevy commented 5 years ago

Awesome. I will test it out. Thanks.

bluebill1049 commented 5 years ago

any luck on this one @aeciolevy ?

aeciolevy commented 5 years ago

it worked! Thanks!