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

fix(overlay): server-side rendering error when creating backdrop element #9448

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/cdk/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class OverlayRef implements PortalOutlet {
private _pane: HTMLElement,
private _config: ImmutableObject<OverlayConfig>,
private _ngZone: NgZone,
private _keyboardDispatcher: OverlayKeyboardDispatcher) {
private _keyboardDispatcher: OverlayKeyboardDispatcher,
private _document: Document) {

if (_config.scrollStrategy) {
_config.scrollStrategy.attach(this);
Expand Down Expand Up @@ -259,7 +260,9 @@ export class OverlayRef implements PortalOutlet {

/** Attaches a backdrop for this overlay. */
private _attachBackdrop() {
this._backdropElement = document.createElement('div');
const showingClass = 'cdk-overlay-backdrop-showing';

this._backdropElement = this._document.createElement('div');
this._backdropElement.classList.add('cdk-overlay-backdrop');

if (this._config.backdropClass) {
Expand All @@ -275,13 +278,17 @@ export class OverlayRef implements PortalOutlet {
this._backdropElement.addEventListener('click', () => this._backdropClick.next(null));

// Add class to fade-in the backdrop after one frame.
this._ngZone.runOutsideAngular(() => {
requestAnimationFrame(() => {
if (this._backdropElement) {
this._backdropElement.classList.add('cdk-overlay-backdrop-showing');
}
if (typeof requestAnimationFrame !== 'undefined') {
this._ngZone.runOutsideAngular(() => {
requestAnimationFrame(() => {
if (this._backdropElement) {
this._backdropElement.classList.add(showingClass);
}
});
});
});
} else {
this._backdropElement.classList.add(showingClass);
}
}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/cdk/overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,15 @@ export class Overlay {
create(config?: OverlayConfig): OverlayRef {
const pane = this._createPaneElement();
const portalOutlet = this._createPortalOutlet(pane);
return new OverlayRef(portalOutlet, pane, new OverlayConfig(config), this._ngZone,
this._keyboardDispatcher);

return new OverlayRef(
portalOutlet,
pane,
new OverlayConfig(config),
this._ngZone,
this._keyboardDispatcher,
this._document
);
}

/**
Expand Down