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

Autoupdate: Pass in empty reference element instead of target #237

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

jgerigmeyer
Copy link
Member

Fixes #236
I think fixes #175 also?

Copy link

netlify bot commented Aug 30, 2024

Deploy Preview for anchor-position-wpt canceled.

Name Link
🔨 Latest commit a66ce80
🔍 Latest deploy log https://app.netlify.com/sites/anchor-position-wpt/deploys/66d22b12cf00090008cdbb2a

const lastSuccessful = target.getAttribute(
'data-anchor-polyfill-last-successful',
);
if (lastSuccessful) {
target.setAttribute('data-anchor-polyfill', lastSuccessful);
}
checking = false;
Copy link
Member Author

Choose a reason for hiding this comment

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

In practice, this checking rigamarole seems to be entirely pointless, and never fires an update with checking === true 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, I also couldn't get it to fire while checking = true. However, I didn't see any clear guarantee that it wouldn't be true, and couldn't find a way to throttle CPU in a polyfillable browser. I'd say it doesn't hurt to keep it?

Copy link
Contributor

@jamesnw jamesnw left a comment

Choose a reason for hiding this comment

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

That seems to work well! Nice change!

I agree this fixes #175 .

@@ -369,7 +370,7 @@ async function applyPositionFallbacks(
const offsetParent = await getOffsetParent(target);

autoUpdate(
target,
{} as VirtualElement,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment about how this change works? Should we be passing in the anchor element here for some reason?

Copy link
Member Author

@jgerigmeyer jgerigmeyer Aug 30, 2024

Choose a reason for hiding this comment

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

I don't think we want to react to changes to the anchor element in this case, because we only care about whether the target is overflowing or not. This is a bit of a hacky workaround that depends on the internals of floating-ui, but I added a comment that matches my current understanding.

const lastSuccessful = target.getAttribute(
'data-anchor-polyfill-last-successful',
);
if (lastSuccessful) {
target.setAttribute('data-anchor-polyfill', lastSuccessful);
}
checking = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, I also couldn't get it to fire while checking = true. However, I didn't see any clear guarantee that it wouldn't be true, and couldn't find a way to throttle CPU in a polyfillable browser. I'd say it doesn't hurt to keep it?

@@ -369,7 +370,7 @@ async function applyPositionFallbacks(
const offsetParent = await getOffsetParent(target);

autoUpdate(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we find a way to call the cleanup function this returns? Or perhaps that's part of #91 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, and yes I think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed an issue: #240

@jgerigmeyer jgerigmeyer merged commit 9f97d81 into position-try Sep 3, 2024
8 checks passed
@jgerigmeyer jgerigmeyer deleted the fix-performance branch September 3, 2024 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants