Skip to content

Commit cd76857

Browse files
authored
feat: rename getSingleSpaExtraProviders to provideSingleSpaPlatform & add provideSingleSpa() (#567)
BREAKING CHANGE: getSingleSpaExtraProviders has been renamed to provideSingleSpaPlatform to better align with Angular's naming conventions for provider functions. Before: const platformRef = platformBrowser(getSingleSpaExtraProviders()); After: const platformRef = platformBrowser(provideSingleSpaPlatform()); Also added provideSingleSpa, a new environment provider to be used at the application level (e.g. in bootstrapApplication or an NgModule).
1 parent 6164c31 commit cd76857

14 files changed

Lines changed: 87 additions & 32 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ The package has been republished under the `@single-spa-community` scope due to
2727
| `21.x` | `21.x` |
2828
| `20.x` | `20.x` |
2929
| `19.x` | `19.x` |
30+
31+
> **Note:** This package follows a lock-step versioning strategy — the major version is aligned with Angular's major version to make compatibility obvious at a glance. This means a major bump does not necessarily indicate a breaking change in this package's own API.

apps/chat/src/app/app.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { APP_BASE_HREF } from '@angular/common';
22
import type { ApplicationConfig } from '@angular/core';
33
import { provideRouter } from '@angular/router';
4+
import { provideSingleSpa } from '@single-spa-community/angular';
45

56
import { routes } from './app.routes';
67

78
export const appConfig: ApplicationConfig = {
8-
providers: [{ provide: APP_BASE_HREF, useValue: '/chat' }, provideRouter(routes)],
9+
providers: [
10+
provideSingleSpa(),
11+
{ provide: APP_BASE_HREF, useValue: '/chat' },
12+
provideRouter(routes),
13+
],
914
};

apps/chat/src/main.single-spa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NavigationStart, Router } from '@angular/router';
2-
import { getSingleSpaExtraProviders, singleSpaAngular } from '@single-spa-community/angular';
2+
import { provideSingleSpaPlatform, singleSpaAngular } from '@single-spa-community/angular';
33

44
import { singleSpaPropsSubject } from './single-spa/single-spa-props';
55
import { bootstrapApplication, platformBrowser } from '@angular/platform-browser';
@@ -8,7 +8,7 @@ import { appConfig } from './app/app.config';
88

99
const lifecycles = singleSpaAngular({
1010
bootstrapFunction: async singleSpaProps => {
11-
const platformRef = platformBrowser(getSingleSpaExtraProviders());
11+
const platformRef = platformBrowser(provideSingleSpaPlatform());
1212
singleSpaPropsSubject.next(singleSpaProps);
1313
const appRef = await bootstrapApplication(AppComponent, appConfig, { platformRef });
1414
appRef.onDestroy(() => {

apps/elements/src/main.single-spa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { singleSpaAngularElements } from '@single-spa-community/angular/elements';
2-
import { getSingleSpaExtraProviders } from '@single-spa-community/angular';
2+
import { provideSingleSpaPlatform } from '@single-spa-community/angular';
33

44
import { AppModule } from './app/app.module';
55

@@ -12,7 +12,7 @@ const lifecycles = singleSpaAngularElements({
1212
bootstrapFunction: async () => {
1313
unmountableStyles.use();
1414

15-
const ngModuleRef = await platformBrowser(getSingleSpaExtraProviders()).bootstrapModule(
15+
const ngModuleRef = await platformBrowser(provideSingleSpaPlatform()).bootstrapModule(
1616
AppModule,
1717
);
1818

apps/navbar/src/app/app.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { APP_BASE_HREF } from '@angular/common';
22
import { ApplicationConfig } from '@angular/core';
33
import { provideRouter } from '@angular/router';
4+
import { provideSingleSpa } from '@single-spa-community/angular';
45

56
import { routes } from './app.routes';
67

78
export const appConfig: ApplicationConfig = {
89
providers: [
10+
provideSingleSpa(),
11+
912
{
1013
provide: APP_BASE_HREF,
1114
useValue: '/',

apps/navbar/src/main.single-spa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { NavigationStart, Router } from '@angular/router';
22
import { bootstrapApplication, platformBrowser } from '@angular/platform-browser';
3-
import { getSingleSpaExtraProviders, singleSpaAngular } from '@single-spa-community/angular';
3+
import { provideSingleSpaPlatform, singleSpaAngular } from '@single-spa-community/angular';
44

55
import { appConfig } from './app/app.config';
66
import { AppComponent } from './app/app.component';
77

88
const lifecycles = singleSpaAngular({
99
bootstrapFunction: () => {
10-
const platformRef = platformBrowser(getSingleSpaExtraProviders());
10+
const platformRef = platformBrowser(provideSingleSpaPlatform());
1111
return bootstrapApplication(AppComponent, appConfig, { platformRef });
1212
},
1313
template: '<navbar-root />',

apps/parcel/src/main.single-spa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { bootstrapApplication, platformBrowser } from '@angular/platform-browser';
2-
import { getSingleSpaExtraProviders, singleSpaAngular } from '@single-spa-community/angular';
2+
import { provideSingleSpaPlatform, singleSpaAngular } from '@single-spa-community/angular';
33

44
import { AppComponent } from './app/app.component';
55

66
const lifecycles = singleSpaAngular({
77
bootstrapFunction: () => {
8-
const platformRef = platformBrowser(getSingleSpaExtraProviders());
8+
const platformRef = platformBrowser(provideSingleSpaPlatform());
99
return bootstrapApplication(
1010
AppComponent,
1111
{

apps/shop/src/app/app.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { APP_BASE_HREF } from '@angular/common';
22
import type { ApplicationConfig } from '@angular/core';
33
import { provideRouter } from '@angular/router';
4+
import { provideSingleSpa } from '@single-spa-community/angular';
45

56
import { routes } from './app.routes';
67

78
export const appConfig: ApplicationConfig = {
8-
providers: [{ provide: APP_BASE_HREF, useValue: '/shop' }, provideRouter(routes)],
9+
providers: [
10+
provideSingleSpa(),
11+
{ provide: APP_BASE_HREF, useValue: '/shop' },
12+
provideRouter(routes),
13+
],
914
};

apps/shop/src/main.single-spa.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NavigationStart, Router } from '@angular/router';
22
import { bootstrapApplication, platformBrowser } from '@angular/platform-browser';
3-
import { singleSpaAngular, getSingleSpaExtraProviders } from '@single-spa-community/angular';
3+
import { singleSpaAngular, provideSingleSpaPlatform } from '@single-spa-community/angular';
44

55
import { loadMontserrat } from './fonts';
66
import { appConfig } from './app/app.config';
@@ -9,7 +9,7 @@ import { AppComponent } from './app/app.component';
99
const lifecycles = singleSpaAngular({
1010
bootstrapFunction: async () => {
1111
await loadMontserrat();
12-
const platformRef = platformBrowser(getSingleSpaExtraProviders());
12+
const platformRef = platformBrowser(provideSingleSpaPlatform());
1313
return bootstrapApplication(AppComponent, appConfig, { platformRef });
1414
},
1515
template: '<shop-root />',

libs/single-spa-community-angular/src/extra-providers.ts renamed to libs/single-spa-community-angular/src/platform-providers.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { switchMap } from 'rxjs/operators';
1010

1111
import { runOutsideAngular } from './run-outside-angular';
1212

13-
declare const Zone: any;
14-
1513
export class SingleSpaPlatformLocation extends BrowserPlatformLocation {
1614
// When `pushState` or `replaceState` is called, single-spa will dispatch a synthetic
1715
// `popstate` event to notify other apps of the URL change. We use this flag to
@@ -95,14 +93,6 @@ export class SingleSpaPlatformLocation extends BrowserPlatformLocation {
9593
}
9694

9795
onPopState(fn: LocationChangeListener): VoidFunction {
98-
// Wrap the listener in the current Zone.js zone so that Angular's change detection
99-
// is triggered correctly when the listener runs. This is necessary because popstate
100-
// events from browser back/forward navigation are dispatched in the root zone, outside
101-
// of Angular's zone. single-spa overrides `history.replaceState`, which prevents
102-
// Angular's zone from intercepting these events automatically.
103-
// See https://github.com/single-spa/single-spa-angular/issues/94 for full context.
104-
fn = typeof Zone !== 'undefined' && Zone?.current ? Zone.current.wrap(fn, this.source) : fn;
105-
10696
const onPopStateListener = (event: LocationChangeEvent) => {
10797
// Instead of calling `fn` directly, push the event into the Subject so it can be
10898
// debounced and deferred via the switchMap + timer pipeline in the constructor.
@@ -124,7 +114,7 @@ export class SingleSpaPlatformLocation extends BrowserPlatformLocation {
124114
* @example
125115
* const lifecycles = singleSpaAngular({
126116
* bootstrapFunction: async () => {
127-
* const platformRef = platformBrowser(getSingleSpaExtraProviders());
117+
* const platformRef = platformBrowser(provideSingleSpaPlatform());
128118
* return bootstrapApplication(AppComponent, appConfig, { platformRef });
129119
* },
130120
* template: '<app-root />',
@@ -133,7 +123,7 @@ export class SingleSpaPlatformLocation extends BrowserPlatformLocation {
133123
* NavigationStart,
134124
* });
135125
*/
136-
export function getSingleSpaExtraProviders(): StaticProvider[] {
126+
export function provideSingleSpaPlatform(): StaticProvider[] {
137127
return [
138128
{
139129
provide: SingleSpaPlatformLocation,

0 commit comments

Comments
 (0)