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): better handling of server-side rendering #8422

Merged
merged 1 commit into from
Nov 20, 2017

Conversation

crisbeto
Copy link
Member

Fixes multiple server-side rendering issues in the overlay that were causing errors when an overlay is opened in Universal.

Fixes #8412.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 13, 2017
@@ -14,7 +14,7 @@ import {
SkipSelf,
OnDestroy,
} from '@angular/core';
import {Platform} from '@angular/cdk/platform';
import {DOCUMENT} from '@angular/platform-browser';
Copy link
Member

Choose a reason for hiding this comment

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

The DOCUMENT from platform-browser is deprecated; should use the one from @angular/common instead

// causes TypeScript to preserve the constructor signature types.
this._liveElement = elementToken || this._createLiveElement();
}
@Inject(DOCUMENT) private _document: any) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can do:

@Inject(DOCUMENT) private _document: Document|Document

It shouldn't preserve the type info for "computed" types; I think this will trick it will still giving type safety

Copy link
Member Author

Choose a reason for hiding this comment

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

That doesn't seem to work in AoT.

deps: [[new Optional(), new SkipSelf(), OverlayKeyboardDispatcher]],
deps: [
[new Optional(), new SkipSelf(), OverlayKeyboardDispatcher],
DOCUMENT as InjectionToken<any> // We need to use the InjectionToken somewhere to keep TS happy
Copy link
Member

Choose a reason for hiding this comment

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

// Coerce to `InjectionToken` so that the `deps` match the "shape"
// of the type expected by Angular

element.parentNode.insertBefore(this._wrapper, element);
this._wrapper.appendChild(element);
this._wrapper = this._document.createElement('div');
this._wrapper!.classList.add('cdk-global-overlay-wrapper');
Copy link
Member

Choose a reason for hiding this comment

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

Put the ! on the assignment for _wrapper?

this._wrapper = this._document.createElement('div')!;

Copy link
Member Author

Choose a reason for hiding this comment

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

TS can't figure it out when assigning to a property.

Fixes multiple server-side rendering issues in the overlay that were causing errors when an overlay is opened in Universal.

Fixes angular#8412.
@crisbeto
Copy link
Member Author

Addressed the feedback @jelbourn.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Nov 14, 2017
@jelbourn jelbourn merged commit 0f83b20 into angular:master Nov 20, 2017
@crisbeto crisbeto mentioned this pull request Dec 27, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get document is undefined with SSR in MatSnackBar
3 participants