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

feat: CXSPA-5903 Schematics - add provideHttpClient(withFetch(), withInterceptorsFromDi()) in fresh applications #18443

Merged
merged 11 commits into from
Feb 7, 2024

Conversation

pawelfras
Copy link
Contributor

@pawelfras pawelfras commented Feb 2, 2024

This PR contains changes related usage of provideHttpClient(withFetch(), withInterceptorsFromDi()) in new Spartacus applications as well as in our internal storefront application. Such a change allows us to avoid warning during Spartacus installation:

NG02801: Angular detected that `HttpClient` is not configured to use `fetch` APIs. It's strongly recommended to enable
`fetch` for applications that use Server-Side Rendering for better performance and compatibility. To enable `fetch`, add the
'withFetch()` to the `provideHttpClient()` call at the root of the application.

This change is applied for both client-side rendering and server-side rendering.

In addition to withFetch config, withInterceptorsFromDi has to be applied to include class-based interceptors configured using a multi-provider in the injector into the configured HttpClient instance.

Changes:

  • provideHttpClient(withFetch()) instead of HttpClientModule in fresh Spartacus applications
  • adjust the schematics logic responsible for removing provideClientHydration to remove only the intended provider
  • provideHttpClient(withFetch()) instead of HttpClientModule in the storefront app module
  • unit test adjustments

QA steps:

  • CSR:

    • build and deploy Spartacus packages locally:
      npx ts-node ./tools/schematics/testing.ts in the SPA root folder
    • generate fresh ng17 application:
      npx @angular/cli new my-app --standalone=false --ssr=false --style=scss
    • go to the project's directory install Spartacus from local packages:
      npx @angular/cli add @spartacus/schematics@latest --baseUrl="https://40.76.109.9:9002"
    • verify whether app.module.ts contains provideHttpClient(withFetch(), withInterceptorsFromDi()) configuration
    • run npm run start to verify if the app works
  • SSR:

    • build and deploy Spartacus packages locally:
      npx ts-node ./tools/schematics/testing.ts in the SPA root folder
    • generate fresh ng17 application:
      npx @angular/cli new my-app --standalone=false --ssr=false --style=scss
    • go to the project's directory and install Spartacus with SSR from local packages:
      npx @angular/cli add @spartacus/schematics@latest --baseUrl="https://40.76.109.9:9002" --ssr
    • verify whether app.module.ts contains provideHttpClient(withFetch(), withInterceptorsFromDi()) configuration (the additional coma is related to the removal of provideClientHydration feature)
    • run npm run build and npm run serve:ssr:my-app to verify if the app works

closes CXSPA-5903

… fresh applications

- `provideHttpClient(withFetch()) instead of `HttpClientModule` in fresh Spartacus applications
- adjust logic responsible for removing `provideClientHydration` to remove only intended provider
- `provideHttpClient(withFetch()) instead of `HttpClientModule` in storefront app module
- unit tests adjustments
@pawelfras pawelfras marked this pull request as ready for review February 2, 2024 15:24
@pawelfras pawelfras requested a review from a team as a code owner February 2, 2024 15:24
@github-actions github-actions bot marked this pull request as draft February 2, 2024 15:33
@pawelfras pawelfras marked this pull request as ready for review February 2, 2024 15:33
@github-actions github-actions bot marked this pull request as draft February 2, 2024 15:33
@pawelfras pawelfras marked this pull request as ready for review February 2, 2024 15:34
@github-actions github-actions bot marked this pull request as draft February 2, 2024 15:34
@pawelfras pawelfras marked this pull request as ready for review February 3, 2024 06:58
@github-actions github-actions bot marked this pull request as draft February 3, 2024 08:26
Copy link

cypress bot commented Feb 3, 2024

4 flaky tests on run #42560 ↗︎

0 119 2 0 Flakiness 4
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge c855e1b into b4f2abe...
Project: spartacus Commit: a6f74d833b ℹ️
Status: Passed Duration: 13:04 💡
Started: Feb 7, 2024 9:01 AM Ended: Feb 7, 2024 9:14 AM

Review all test suite changes for PR #18443 ↗︎

@pawelfras pawelfras marked this pull request as ready for review February 5, 2024 09:31
@github-actions github-actions bot marked this pull request as draft February 5, 2024 10:56
@pawelfras pawelfras marked this pull request as ready for review February 5, 2024 12:46
@github-actions github-actions bot marked this pull request as draft February 5, 2024 14:12
@pawelfras pawelfras changed the title feat: CXSPA-5903 Schematics - add provideHttpClient(withFetch()) in fresh applications feat: CXSPA-5903 Schematics - add provideHttpClient(withFetch(), withInterceptorsFromDi()) in fresh applications Feb 6, 2024
@pawelfras pawelfras marked this pull request as ready for review February 6, 2024 10:15
@github-actions github-actions bot marked this pull request as draft February 6, 2024 13:21
@pawelfras pawelfras marked this pull request as ready for review February 6, 2024 13:23
@github-actions github-actions bot marked this pull request as draft February 6, 2024 13:47
Copy link
Contributor

@Platonn Platonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QAd. LGTM.

@pawelfras pawelfras marked this pull request as ready for review February 6, 2024 18:16
@github-actions github-actions bot marked this pull request as draft February 7, 2024 07:21
@pawelfras pawelfras marked this pull request as ready for review February 7, 2024 07:57
@github-actions github-actions bot marked this pull request as draft February 7, 2024 08:36
@pawelfras pawelfras marked this pull request as ready for review February 7, 2024 08:52
@pawelfras pawelfras merged commit a87e3b7 into develop-next-major Feb 7, 2024
26 checks passed
@pawelfras pawelfras deleted the feat/CXSPA-5903 branch February 7, 2024 09:19
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

Successfully merging this pull request may close these issues.

2 participants