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

Upgrade for Angular 9 #180

Closed
wants to merge 9 commits into from
Closed

Conversation

henrahmagix
Copy link

Followed official upgrade instructions https://update.angular.io/#8.0:9.0l3 and did a bit of pruning

…ular/common@8 @angular/cdk@8 @angular/material@8

Used --force to get past tsickle peer dependency:
>Package "tsickle" has an incompatible peer dependency to "typescript" (requires "~3.4.1", would install "3.5.3").
…latest, @angular/common@latest, @angular/cdk@latest, @angular/material@latest
Angular Workspace migration. Update an Angular CLI workspace to version 9.
Static flag migration. Removes the `static` flag from dynamic queries. As of Angular 9, the "static" flag defaults to false and is no longer required for your view and content queries. Read more about this here: https://v9.angular.io/guide/migration-dynamic-flag
Updates Angular Material to v9
@alecdewitz
Copy link

Any plans to merge this soon? @willshowell

@isaackehle
Copy link
Member

We had been trying to keep them at a base level, not to versions > x.0.0. Can you please back them down to 9.0.0 as applicable?

@isaackehle
Copy link
Member

Also, I tried building locally w/ no success. What version of node?

@julianobrasil
Copy link
Contributor

julianobrasil commented Apr 8, 2020

Man... I accidentally deleted my last post 😄.

Also, I tried building locally w/ no success. What version of node?

@pgkehle and @henrahmagix, after switching "module": "ESNext" to "module": "CommonJS" in tsconfig.json I could successfully build the project (after rebasing it and solving that package-lock.json conflict). You can see some explanation here: https://github.com/TypeStrong/ts-node#syntaxerror

I'm using node v13.10.1

@isaackehle
Copy link
Member

@julianobrasil do you get any warnings/errors in the demo? Mine builds and runs now, but I get these warnings:

There is no directive with "exportAs" set to "satPopoverAnchor"
'sat-popover' is not a known element:

Also, npm run lint:

> @ncstate/sat-popover@4.0.0 lint /Users/pgkehle/code/popover-h
> ng lint popover --type-check

Linting "popover"...

WARNING: /Users/pgkehle/code/popover-h/src/lib/popover/popover-anchoring.service.ts:280:31 - keyCode is deprecated.
WARNING: /Users/pgkehle/code/popover-h/src/lib/popover/popover.component.ts:308:32 - FocusTrapFactory is deprecated: Use `ConfigurableFocusTrapFactory` instead.

@julianobrasil
Copy link
Contributor

julianobrasil commented Apr 9, 2020

I haven't run anything yesterday, but I'll mess a little bit with it today. One thing that I've noticed by running the demo (npm run demo) is that, in anchor-reuse.component.ts, you need to change a little bit the @ViewChild() statements on these lines:

@ViewChild('a', { static: false }) aPopover: SatPopover;
@ViewChild('b', { static: false }) bPopover: SatPopover;

I looks like something changed in angular 9 and you now need to run the queries before the first change detection cycle to avoid an error message on devtools console, or you will have trouble here when calling getActivePopover() before the queries have been executed internally by angular:

<button
mat-button
*ngIf="showAnchor"
[satPopoverAnchor]="getActivePopover()"
(click)="getActivePopover().toggle()"
>
Anchor
</button>

You can solve that by just setting the static property to true on @ViewChild():

  @ViewChild('a', {static: true}) aPopover: SatPopover;
  @ViewChild('b', {static: true}) bPopover: SatPopover;

I'll dig in the other things you've pointed out.

@Pes8
Copy link

Pes8 commented Apr 9, 2020

WHEN

@julianobrasil
Copy link
Contributor

julianobrasil commented Apr 9, 2020

@pgkehle, concerning the first warning message about the keyCode in popover-anchoring.service.ts, well, it's a known issue that angular team has chosen to not change until they stop supporting IE11 (see angular/components#7374 (comment)). We can just avoid that message by disabling the lint check for that line.

Instead of:

filter(event => event.keyCode === ESCAPE),

We can just:

// TODO: remove this line when angular stop supporting IE11 and cdk provides
//   other methods to check for the key codes in a safe way.
// tslint:disable-next-line: deprecation
filter(event => event.keyCode === ESCAPE),

@julianobrasil
Copy link
Contributor

julianobrasil commented Apr 9, 2020

@pgkehle, the second warning is about an update of cdk a11y API. Originally there was a FocusTrapFactory.create() method, which is now deprecated in favor of ConfigurableFocusTrapFactory.create() method.

The basic difference is that the deprecated one received a boolean as its second parameter:

create(element: HTMLElement, deferCaptureElements: boolean = false): ConfigurableFocusTrap {
  ...
}

The new ConfigurableFocusTrapFactory.create, instead of a boolean, receives a ConfigurableFocusTrapConfig object:

/**
   * Creates a focus-trapped region around the given element.
   * @param element The element around which focus will be trapped.
   * @param config The focus trap configuration.
   * @returns The created focus trap instance.
   */
  create(element: HTMLElement, config?: ConfigurableFocusTrapConfig): ConfigurableFocusTrap;

As you can see, the second argument is optional, and, internally, its default value is {defer: false}.

We are not using the second parameter and, in cdk code, its default value is still false for the deferring thing:

this._focusTrap = this._focusTrapFactory.create(this._focusTrapElement.nativeElement);

By switching FocusTrapFactory to ConfigurableFocusTrapFactory, without any other change in the class, the current unit tests pass. So I think it's safe to switch classes.

@julianobrasil
Copy link
Contributor

What do you thinking we should do now? Should we wait for @henrahmagix to fix all of the issues in this single PR?

Or, as an alternative, he could just fix the rebasing and the "module": "CommonJS". The warning about FocusTrapFactory would be taken care of in a tiny separate PR.

@julianobrasil
Copy link
Contributor

julianobrasil commented Apr 9, 2020

@julianobrasil do you get any warnings/errors in the demo? Mine builds and runs now, but I get these warnings:

There is no directive with "exportAs" set to "satPopoverAnchor"
'sat-popover' is not a known element:

I think you're referring to the IDE's warnings (I didn't get this warning on the command line and I think it's just something related to @angular/language-service). They go away if you step back from using Ivy in development typescript configs (Ivy is not recommended for libraries anyway) in tsconfig.lib.ts.

"angularCompilerOptions": {
    "skipTemplateCodegen": true,
    "strictMetadataEmit": true,
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "enableIvy": false <= added
},

npm run build (with Ivy):

image

npm run build (w/o Ivy):

image

npm run build:demo

image

npm run demo

image

npm run test:once

image

@isaackehle
Copy link
Member

@julianobrasil Yes, I was referring to the IDE warnings in vs-code. If it is related just to the IDE, which it seems you just proved, then while it would be nice to find a solution for vs-code, it's not something we need to worry about.

Thanks for all of that digging. I'd agree that we should get this PR merged then do a smaller follow up for the bugs, like you suggested. While @willshowell and I were trying to keep this on the major change revision, it's just going to have to be a major release for this project.

@henrahmagix Can you please submit the change to using CommonJS today, and we'll get this merged?

femave added a commit to femave/popover that referenced this pull request Jun 25, 2020
femave added a commit to femave/popover that referenced this pull request Jun 25, 2020
@isaackehle isaackehle closed this Jun 27, 2020
@isaackehle
Copy link
Member

Obsoleted by #185

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants