-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssr): fix lazy-loading functionality
* add global provider to StylesheetMap to prevent lazy loading from instantiating multiple copies * add global provider to MatchMedia to ensure that the right version is instantiated in lazy modules
- Loading branch information
1 parent
bbe4b23
commit d4f2514
Showing
10 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import {InjectionToken, NgZone, Optional, PLATFORM_ID, SkipSelf} from '@angular/core'; | ||
import {DOCUMENT} from '@angular/common'; | ||
|
||
import {MatchMedia} from '../match-media/match-media'; | ||
|
||
/** | ||
* Ensure a single global service provider | ||
*/ | ||
export function MATCH_MEDIA_PROVIDER_FACTORY(parentMedia: MatchMedia, | ||
ngZone: NgZone, | ||
platformId: Object, | ||
_document: Document) { | ||
return parentMedia || new MatchMedia(ngZone, platformId, _document); | ||
} | ||
|
||
|
||
/** | ||
* Export provider that uses a global service factory (above) | ||
*/ | ||
export const MATCH_MEDIA_PROVIDER = { | ||
provide : MatchMedia, | ||
deps : [ | ||
[ new Optional(), new SkipSelf(), MatchMedia ], | ||
NgZone, | ||
<InjectionToken<Object>>PLATFORM_ID, | ||
<InjectionToken<Document>>DOCUMENT, | ||
], | ||
useFactory : MATCH_MEDIA_PROVIDER_FACTORY | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
export * from './stylesheet-map'; | ||
export * from './stylesheet-map-provider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import {Optional, SkipSelf} from '@angular/core'; | ||
|
||
import {StylesheetMap} from './stylesheet-map'; | ||
|
||
/** | ||
* Ensure a single global service provider | ||
*/ | ||
export function STYLESHEET_MAP_PROVIDER_FACTORY(parentSheet: StylesheetMap) { | ||
return parentSheet || new StylesheetMap(); | ||
} | ||
|
||
|
||
/** | ||
* Export provider that uses a global service factory (above) | ||
*/ | ||
export const STYLESHEET_MAP_PROVIDER = { | ||
provide: StylesheetMap, | ||
deps: [ | ||
[new Optional(), new SkipSelf(), StylesheetMap], | ||
], | ||
useFactory: STYLESHEET_MAP_PROVIDER_FACTORY | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters