question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

window.google object is gone after unmount and mount the Lazy-loading Wrapper Component.

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
codewithcatscommented, Aug 7, 2016

It seems like window.google is reset every time. My current workaround is make a change in GoogleApi: from

let google = window.google == null;

to

let google = window.google || null;
1reaction
Szarkocommented, Aug 1, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found