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(universal): gate several browser-specific bits on being on the browser #4251

Merged
merged 3 commits into from
May 11, 2017

Conversation

jelbourn
Copy link
Member

Related to #308

This is really a temporary fix until we have a secondary @angular/material/server entry-point which can contain things like NoopScrollDispatcher, 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

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Apr 24, 2017
Copy link
Contributor

@mmalerba mmalerba left a 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();
Copy link
Contributor

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)

// 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()) {
Copy link
Member

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();
Copy link
Member

@crisbeto crisbeto Apr 25, 2017

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
}

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 would then no longer be using the cached version if there is one.

@@ -0,0 +1,4 @@
/** Gets whether the current platform is a web browser (versus node). */
export function isBrowser() {
return typeof document === 'object';
Copy link
Member

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 if document is null.
  • 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.

Copy link
Member Author

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.

@jelbourn
Copy link
Member Author

jelbourn commented Apr 25, 2017

Replaced implementation from yesterday with a new approach that adds isBrowser to the existing Platform injectable. This will make it easier to test/fake in places where that would be necessary.

This led to a tangent of having to fix some modules and tests that were adding providers directly instead of importing the module where the provider lives.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba
Copy link
Contributor

LGTM, needs rebase though

@jelbourn
Copy link
Member Author

Rebased

@jelbourn
Copy link
Member Author

@mmalerba fixed circular dep

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Apr 26, 2017
@mmalerba mmalerba removed the action: merge The PR is ready for merge by the caretaker label Apr 28, 2017
@mmalerba
Copy link
Contributor

@jelbourn needs rebase and investigation into failing test

@jelbourn
Copy link
Member Author

@mmalerba after I rebased the error went away

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Apr 28, 2017
@mmalerba mmalerba removed the action: merge The PR is ready for merge by the caretaker label Apr 28, 2017
@mmalerba
Copy link
Contributor

@jelbourn sorry, needs more rebasing

@jelbourn
Copy link
Member Author

Rebased again- weirdly, git couldn't auto-resolve the conflicts, but WebStorm could

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Apr 29, 2017
@jelbourn
Copy link
Member Author

jelbourn commented May 3, 2017

@andrewseguin rebased again

@aitboudad
Copy link
Contributor

tried on my side and I got some little issues:

  • missing rxjs of import
  • navigator is not defined in Platform

@mmalerba mmalerba removed the action: merge The PR is ready for merge by the caretaker label May 8, 2017
@mmalerba
Copy link
Contributor

mmalerba commented May 8, 2017

still has some lint issues and failing tests too

@jelbourn jelbourn force-pushed the universal branch 4 times, most recently from 85d3ba4 to 27778ad Compare May 10, 2017 21:25
@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label May 10, 2017
@jelbourn
Copy link
Member Author

@kara rebased again and green again

@kara kara merged commit f27df86 into angular:master May 11, 2017
devversion added a commit to devversion/material2 that referenced this pull request May 12, 2017
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.
devversion added a commit to devversion/material2 that referenced this pull request May 16, 2017
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.
jelbourn pushed a commit that referenced this pull request May 17, 2017
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.
@jelbourn jelbourn deleted the universal branch September 13, 2017 04:38
@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.

6 participants