-
Notifications
You must be signed in to change notification settings - Fork 821
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
Clusters are breaking the universal app #1241
Comments
@lazarljubenovic yeah wrapping would be a good solution for now. |
I will look into this |
@lazarljubenovic I don't have any experience with universal apps, and I'm not sure how to use |
@jigfox Sure! You can inject the token constructor(@Inject(PLATFORM_ID) private platformId: any) {
} Then you can use Angular functions such as constructor(@Inject(PLATFORM_ID) private platformId: any) {
if (isPlatformBrowser(this.platformId)) {
console.log('This code runs only in browser')
}
} |
I'm not sure where to put this, the call to markerclusterer.js#L698 and markerclusterer.js#L1270 so cluster-manager.ts#L3 should be wrapped? Maybe it's necessary to disable the whole cluster plugin on not Browser platforms? But maybe a rewrite markerclusterer.js could help, because it could be rewritten without a |
Ah, it's code from third-party lib. Jeez. I wonder if just saying something like this would help: const oldWindow = window || {}
window = {
setTimeout: oldWindow.setTimeout
}
import 'js-marker-clusterer'
window = oldWindow But I think that server will break from just finding Could we do the |
By the way, it says on that Google Map repo this:
So what about we just fork that on our own? Since it's a historical repo, it will never change which means there's no problem just using our own tweaked version which doesn't use |
Oh, and regarding this:
This looks very basic but I've only learned this a few day ago: If you try doing I guess I could try playing around and forking our own version of the Cluster repo and see what can be done using this. |
I tried fixing this using the following approach: http://ideasintosoftware.com/typescript-conditional-imports/ But I had no luck, as AOT compiler will start complaining the directive can no longer be found. |
Yeah, AOT compiler statically analyzes the code and thus dynamic imports
sure sound like something that's not possible to do in Angular.
Have you had time trying to fork the repo and just removing access to
`window`? Looks like it's used only in a couple of places that can easily
be avoided.
On Dec 27, 2017 18:06, "cmddavid" <notifications@github.com> wrote:
I tried fixing this using the following approach:
http://ideasintosoftware.com/typescript-conditional-imports/
But I had no luck, as AOT compiler will start complaining the directive can
no longer be found.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1241 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHTnkXZ85QbMrFT7timh9MPWDeL5piYiks5tEnkmgaJpZM4QmwTi>
.
|
Not yet, I might try it later this week. I'm not a fan of changing the source repo though, even though it is not being maintained at this moment, it might be later. But I guess we don't have any other option. I like the suggestion to completely remove the window references, if that would be possible that would be great. |
Well, it's been two years since the last update so that's why I think
forking in this particular instance, at least as a temporary solution,
wouldnt be too bad.
…On Thu, Dec 28, 2017 at 1:04 AM, cmddavid ***@***.***> wrote:
Not yet, I might try it later this week. I'm not a fan of changing the
source repo though, even though it is not being maintained at this moment,
it might be later. But I guess we don't have any other option. I like the
suggestion to completely remove the window references, if that would be
possible that would be great.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1241 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHTnkfZdUcmrInBzlNL41wJ6znRzWVCoks5tEtsHgaJpZM4QmwTi>
.
|
I forked It's published in npm. https://www.npmjs.com/package/js-marker-clusterer-universal
|
@mbrezovsky nice work, it is working well for me. I did get one error related to |
…luster dependency in angular universal build (sebholstein#1241) Replaced js-marker-clusterer dependency to fixed version js-marker-clusterer-universal Fix sebholstein#1241
Any updates on this issue? |
@AoschkA I'm still using the workaround as mentioned in my earlier comment. You can find my example here: |
@cmddavid Your readme just explains how to install agm/js-marker-clusterer. How does one integrate this into our own projects? |
@AoschkA, the repo is just the compiled output, I did not any instructions, you can add it to your package.json like this:
When you install it, you will have the js-marker-clusterer without window is undefined errors, and compiled to ES2015 so it's compatible with services like Firebase. |
Thx that works. Would be nice if this could be implemented in AGM though. But I appreciate the solution @cmddavid ! |
@cmddavid I made like you said, but there is error ERROR in ./node_modules/@agm/js-marker-clusterer/services/managers/cluster-manager.js |
@maksimbykov can you confirm Also worth mentioning I did not check if the package still works with angular 6. |
@cmddavid thank you very much! probably yesterday I was tired and inattentive |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
"@agm/js-marker-clusterer": "git+https://github.com/cmddavid/js-marker-clusterer.git" sorry but it doesn't work(don't install anything) |
Thanks a lot man, you just saved me... kudos :) |
i still have this issue, why is it marked as closed?? |
You literally downvoted the explanation on why it was closed. You've seen why it was closed. |
@lazarljubenovic we are going to move to https://github.com/googlemaps/v3-utility-library/tree/master/packages/markerclustererplus anyway |
so now we can reopen it 💃 anyway is not simpler to import js-marker-clusterer inside the library and create an exportable module? i did this on mine: https://github.com/alexnoise79/js-marker-clusterer (see src/markerclusterer.js) and then on: i replaced declare Markerclusterer with: import * as MarkerClusterer from 'js-marker-clusterer'; it works and compile ssr 100% |
My solution base on @mbrezovsky comment above - so
and it will be installed after all and replaced. |
Issue description
Just importing the cluster module is breaking the app.
Steps to reproduce and a minimal demo of the problem
I have a map where all its markers are under a cluster. The map is wrapped into a conditional so it renders only on client (not on the server) because there are known issues. However, it still breaks the server side rendering because it tries to access
window
at some point. This probably happens during module initialization, since the component itself never got instantiated.Current behavior
Apps using cluster cannot be used in a server side app.
Expected/desired behavior
Apps should not break.
angular & angular-google-maps version
@angular/*
at 5.0.0@agm/core
at 1.0.0-beta.2Other information
I'm looking for a workaround ATM but, of course, would be nice if users having a Universal app do not have to do anything. We should at least wrap all code with
isPlatformBrowser
and just list that as a caveat for now, until we figure out how to render maps on the server, if it's even possible.The text was updated successfully, but these errors were encountered: