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

Migration to the Floating UI #743

Merged

Conversation

pzubar
Copy link
Collaborator

@pzubar pzubar commented Apr 6, 2023

This PR migrates the ember-attacher from Popper to Floating UI.
It also removes the ember-raf-test-waiter in favour of a more modern way to wait for the floating element positioning in the tests (see https://github.com/emberjs/ember-test-waiters).

Motivation

The floating-ui already has its motivation described on the official website:

Floating UI is the evolution of Popper v2, and aims to be a lower-level solution similar to CSS in which you progressively add properties to achieve desired positioning behaviour.

The Floating UI is actively supported by the organization that created the Popper library.

Migration

From the official migrate guide :

Floating UI forked Popper 2 and shares a lot of similarities. While the main external positioning function changed, many other parts of the API are similar.

I could provide the addon's own migration guide if the contributors' team agree to migrate/upgrade to the Floating UI.

What do you think about this proposal? I'll be happy to hear your thoughts.

Comment on lines +140 to +161
@computed('_parentFinder.parentNode', '_renderInPlace', 'floatingElementContainer')
get _floatingElementContainer() {
const maybeContainer = this.floatingElementContainer;
const renderInPlace = this._renderInPlace;
let floatingElementContainer;

if (renderInPlace) {
floatingElementContainer = this._parentFinder.parentNode;
} else if (maybeContainer instanceof Element) {
floatingElementContainer = maybeContainer;
} else if (typeof maybeContainer === 'string') {
const selector = maybeContainer;
const possibleContainers = self.document.querySelectorAll(selector);

assert(`floatingElementContainer selector "${selector}" found `
+ `${possibleContainers.length} possible containers when there should be exactly 1`, possibleContainers.length === 1);

floatingElementContainer = possibleContainers[0];
}

return floatingElementContainer;
}
Copy link
Collaborator Author

@pzubar pzubar Apr 6, 2023

Choose a reason for hiding this comment

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

This is the only part taken from the ember-popper to process the floating element's container logic

Comment on lines 75 to 81
const targetInsideAttachment = find('#attachment-focus-me')
await focus(targetInsideAttachment)
await waitUntil(() => {
if (document.activeElement === targetInsideAttachment) return true

focus(targetInsideAttachment)
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sometimes the "focus" event didn't work for the firs time that caused the flaky tests here

"@html-next/flexi-default-styles": "^2.2.0",
"babel-eslint": "^10.1.0",
"broccoli-asset-rev": "^3.0.0",
"ember-cli": "~3.26.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no changes in the ember-cli version, just sorting the devDependencies alphabetically

@pzubar pzubar marked this pull request as ready for review April 6, 2023 11:00
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

registerApi is redundant because of autoUpdate middleware Introduction

@pzubar pzubar changed the title Upgrades the ember-attacher to the floating-ui instead of popper.js Upgrades to the floating-ui Apr 6, 2023
@krasnoukhov
Copy link
Collaborator

@tylerturdenpants Hey, let me know if this looks good to you, we're wiling to get this addon up-to-date, let me know if you're open to sharing merge/release rights

package.json Outdated
"babel-plugin-filter-imports": "^4.0.0",
"babel6-plugin-strip-class-callcheck": "^6.0.0",
"broccoli-funnel": "^3.0.5",
"ember-auto-import": "^2.6.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added this (and the webpack dependency) to avoid the error caused by the library import in the component

@pzubar
Copy link
Collaborator Author

pzubar commented Apr 11, 2023

@tylerturdenpants could you please take a look when you have time? Thank you!

@pzubar
Copy link
Collaborator Author

pzubar commented Apr 18, 2023

Hey @tylerturdenpants I've noticed the CI failed because of the outdated Node version on CI. I've changed the NODE_VERSION in the ci.yml. Is that enough to fix the fail? Thank you!

@tylerturdenpants
Copy link
Owner

I need to see if @kybishop will give me either more account actions like adding maintainers or transfer the repo to me.

  • @kybishop If you're keeping track with this thread could you please increase my access?

@kybishop
Copy link
Collaborator

I need to see if @kybishop will give me either more account actions like adding maintainers or transfer the repo to me.

  • @kybishop If you're keeping track with this thread could you please increase my access?

@tylerturdenpants I think because it's not under an organization, I can't increase your access. If you delete tylerturdenpants/ember-attacher I can transfer ownership

@tylerturdenpants
Copy link
Owner

@kybishop I have deleted the fork so try again! Hope this works 🤞

@pzubar
Copy link
Collaborator Author

pzubar commented Apr 18, 2023

@tylerturdenpants seems like the only failing CI step now will be the Scenario: ember-release with an error

The Ember Classic edition has been removed. Specifying "classic" in your package.json, or not specifying a value at all, is no longer supported. You must explicitly set the "ember.edition" property to "octane". You can also run npx @ember/octanify to do this.
(the same will happen to ember-beta and ember-canary scenarios)

I think the "octanification" is out of this PR's scope and should be implemented separately. Maybe it makes sense to mark the ember-release as "allowedToFail" as well. Please correct me if I am wrong. Thank you!

@tylerturdenpants
Copy link
Owner

@kybishop one last thing. I would appreciate if you could also transfer NPM admin to me? Tbh, if you want to do all the previous requests with ember-popper, I can take that off your plate. Thank you 😊

Copy link
Owner

Choose a reason for hiding this comment

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

Can we octanify?

Copy link
Collaborator Author

@pzubar pzubar Apr 19, 2023

Choose a reason for hiding this comment

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

Updated to octane edition 🙌

Copy link
Owner

Choose a reason for hiding this comment

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

Let's drop 3.12 support and 3.26 in its place if it all works out. Update the Readme of course 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure! Does it make sense to use 3.28 as an LTS one?

Copy link
Collaborator Author

@pzubar pzubar Apr 19, 2023

Choose a reason for hiding this comment

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

Update the Readme of course

Btw, could you please update the "About" section to fix the demo app URL?

@krasnoukhov
Copy link
Collaborator

@pzubar Should we also have a little guide in README perhaps on how to upgrade to 2.0? Like list out breaking API changes

@pzubar pzubar changed the title Upgrades to the floating-ui Migration to the Floating UI Apr 20, 2023
@pzubar
Copy link
Collaborator Author

pzubar commented Apr 20, 2023

Should we also have a little guide in README perhaps on how to upgrade to 2.0? Like list out breaking API changes

@krasnoukhov great idea! I've added a little guide with a link in README.

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.

None yet

4 participants