-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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(universal): gate several browser-specific bits on being on the browser #4251
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 nit
@@ -126,6 +132,11 @@ export class FocusOriginMonitor { | |||
|
|||
/** Register necessary event listeners on the document and window. */ | |||
private _registerDocumentEvents() { | |||
// Do nothing if we're not on the browser platform. | |||
if (!isBrowser()) { | |||
return Observable.of(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return;
(method isn't expected to return anything)
src/lib/button/button.ts
Outdated
// If not on the browser, say that there are none of the attributes present. | ||
// Since these only affect how the ripple displays (and ripples only happen on the client), | ||
// detecting these attributes isn't necessary when not on the browser. | ||
if (!isBrowser()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nicer if the return below was return isBrowser() && unprefixedAttributeNames.some...
.
@@ -51,6 +54,12 @@ export class ViewportRuler { | |||
* @param documentRect | |||
*/ | |||
getViewportScrollPosition(documentRect = this._documentRect) { | |||
// Cache the document bounding rect so that we don't recompute it for multiple calls. | |||
if (!documentRect) { | |||
this._cacheViewportGeometry(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a little shorter if we made _cacheViewportGeometry
return the documentRect
and then changed the method definition to:
getViewportScrollPosition(documentRect = this._cacheViewportGeometry()) {
// continue as usual
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would then no longer be using the cached version if there is one.
src/lib/core/platform/browser.ts
Outdated
@@ -0,0 +1,4 @@ | |||
/** Gets whether the current platform is a web browser (versus node). */ | |||
export function isBrowser() { | |||
return typeof document === 'object'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things:
- Technically shouldn't be an issue, but
typeof document === 'object'
will be true ifdocument
isnull
. - Perhaps this should be a
const
, instead of a function?
Also I was doing these checks inline in a few places, I don't know whether we shouldn't switch them to use isBrowser
with this PR or in a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed check to typeof document === 'object' && document;
We can get other places in a follow-up.
Replaced implementation from yesterday with a new approach that adds This led to a tangent of having to fix some modules and tests that were adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM, needs rebase though |
Rebased |
@mmalerba fixed circular dep |
@jelbourn needs rebase and investigation into failing test |
@mmalerba after I rebased the error went away |
@jelbourn sorry, needs more rebasing |
Rebased again- weirdly, git couldn't auto-resolve the conflicts, but WebStorm could |
@andrewseguin rebased again |
tried on my side and I got some little issues:
|
still has some lint issues and failing tests too |
85d3ba4
to
27778ad
Compare
@kara rebased again and green again |
With angular#4251 the `ScrollDispatchModule` has been created and it is used by a lot of different components. The class is already exported inside of the file but the core package doesn't export it to the public.
With angular#4251 the `ScrollDispatchModule` has been created and it is used by a lot of different components. The class is already exported inside of the file but the core package doesn't export it to the public.
With #4251 the `ScrollDispatchModule` has been created and it is used by a lot of different components. The class is already exported inside of the file but the core package doesn't export it to the public.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Related to #308
This is really a temporary fix until we have a secondary
@angular/material/server
entry-point which can contain things likeNoopScrollDispatcher
,NoopRippleRenderer
, etc. I don't want to add these classes to the main@angular/material
package both because they would eventually move and they would add bloat for client payload.Also removed a few unnecessary
[class]
bindings while I was around