window.google object is gone after unmount and mount the Lazy-loading Wrapper Component.
See original GitHub issueI don’t really sure why. When the component is unmounted, the window.google is still. But, when the wrapper component is mounted again, the window.google becomes null for unknown reason. I look through the implementation of wrapper and found that the ScriptCache.js loads the Google map script only once and no hope to reload it even if the window.google object is gone away from browser. The solution I’ve temporally did is to recreate my own wrapper with this add-on function.
componentWillUnmount() {
window._scriptMap.delete("google");
}
However, I don’t think it is a good idea to do so. Could you figure out why the window.google object is gone when remounting and fix it?
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Can't perform a React state update on an unmounted ...
I am writing an application in React and was unable to avoid a super common pitfall, which is calling setState(...) after componentWillUnmount(.
Read more >How To Handle Async Data Loading, Lazy Loading, and Code ...
Suspense is a built-in component you use to display a fallback message while the code is loading. Save the file. When you do,...
Read more >@react-google-maps/api - npm
@react-google-maps/api provides very simple bindings to the google maps api and lets you use it in your app as React components.
Read more >Using Google Maps in React without custom libraries
Lazy loading Google Maps library; Mounting your React component inside the maps ... So, simply wrap it with an if (!window.google) phrase.
Read more >6 tips for better React performance | by Aggelos Arvanitakis
TLDR; Try and lazy-load the components that are not actually visible (or needed) to the user until he interacts with them. We are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It seems like
window.google
is reset every time. My current workaround is make a change inGoogleApi
: fromto
I believe I might be facing a similar issue, I have a component on Page A that runs my map component using this module. When navigating to a link to Page B and coming back to Page A the map does not load as the google prop is set to null.
I notice the .loaded is still true though.
Is this what you are describing?
In the documentation when the author describes manually loading the window.google instance, I am not sure what he is referring to. I wonder if using this manual loading would be an alternative solution.