Skip to content
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

Import of HttpClientModule within ngx-md clobbers existing interceptors #159

Open
nuwang opened this issue Oct 20, 2018 · 5 comments
Open

Comments

@nuwang
Copy link

nuwang commented Oct 20, 2018

Ngx-md imports the HttpClientModule internally. However, this will overwrite existing application interceptors, such as the XSRFInterceptor, which can cause module wide misbehaviour.

For a similar issue in another module, please see this issue:
MurhafSousli/ngx-sharebuttons#174

and the corresponding fix:
MurhafSousli/ngx-sharebuttons@a503936#diff-09baae46def54c6afaeed08d24cf8bc2

@vajda
Copy link

vajda commented Nov 30, 2018

Why markdown library even needs HttpClientModule?

@dimpu
Copy link
Owner

dimpu commented Nov 30, 2018

@vajda
We need HttpClientModule for loading external resource when

<ngx-md [path]="'/path/to/code.cpp'"></ngx-md>

@nuwang
We used fetch API to get remote content but to fix #117 issue we had to use HttpClientModule instead.

But I'm trying to understand the issue here. Could you create a https://stackblitz.com/ demo app?

@nuwang
Copy link
Author

nuwang commented Nov 30, 2018

@dimpu Thanks for looking into this. The issue is that the HttpClientModule is only supposed to be imported once per application (as stated in the Angular docs). However, ngx-md imports the HttpClientModule internally, which has bizarre, unintended side-effects. The recommended solution to this issue is to simply not import the HttpClientModule within ngx-md. Instead, users of ngx-md should manually import HttpClientModule at the app level.

For a more full discussion of this issue, see here: angular/angular#20575.
I don't find that Angular's design decision behind this is satisfactorily explained, but nevertheless, the issue itself is clearly described.

In all these cases, the fix is for modules such as ngx-md to not import the HttpClientModule.

@mhamern
Copy link
Contributor

mhamern commented Mar 1, 2019

@dimpu Is this issue being solved?

I spent hours on trying to find where the problem was. It can break your whole app if you for example use interceptor to attach authorization headers to your http request.

Correct way to create a library which needs HttpClientModule is to list it as peer dependency and left it on the user to provide in his module.

I can offer PR if you want, thanks

@dimpu
Copy link
Owner

dimpu commented Mar 1, 2019

@mhamern HttpClientModule is part of @angular/common which is already a peer-dependency. But yes of course if you have better way of solving this. PR would be great. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants