primefaces / primeng

The Most Complete Angular UI Component Library
https://primeng.org
Other
9.53k stars 4.47k forks source link

Fileupload breaks http requests interceptor cycle when imported in a standalone context #15360

Closed pplaissy closed 2 weeks ago

pplaissy commented 2 weeks ago

Describe the bug

Hi!

Say we have a standalone app

// an app config file which register a http interceptor
export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(withInterceptors([
      apiRequestsInterceptor
    ])), 
    provideAuth(authConfig)
  ]
};

// the http interceptor
export const apiRequestsInterceptor: HttpInterceptorFn = (req: HttpRequest<unknown>, next: HttpHandlerFn) => {
  console.log("intercepted");
  // here the access token is added to headers
};

// and finally a component
@Component({
  selector: 'test',
  standalone: true,
  imports: [],
  templateUrl: './test.component.html'
})
export class TestComponent {
}

Everything works fine until I import the Fileupload component. From this import, the interceptor is ignored.

import { FileUploadModule } from 'primeng/fileupload';
@Component({
  selector: 'test',
  standalone: true,
  imports: [FileUploadModule],
  templateUrl: './test.component.html'
})
export class TestComponent {
}

It's because Fileupload imports itself HttpClientModule which is incompatible in standalone context.

I'm going to make a pull request to suggest the fix.

Environment

angular 17 standalone app

Reproducer

https://stackblitz.com/edit/github-7yclho?file=src%2Fapp%2Fapp.component.html

Angular version

17.3.5

PrimeNG version

17.14

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

0

Browser(s)

No response

Steps to reproduce the behavior

  1. Open the console to see if the request was intercepted.
  2. click on the 'end api call' button
  3. nothing to see in the console -> the requests are not intercepted
  4. remove the FileUpload import in the app.component.ts file
  5. click on the 'end api call' button
  6. the console log display 'intercepted' on each click

Expected behavior

No response

cetincakiroglu commented 2 weeks ago

Fixed in https://github.com/primefaces/primeng/issues/15360