question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

make Popper#update sync + make scheduleUpdate return promise

See original GitHub issue

CodePen Demo

https://codepen.io/anon/pen/NwZQwK

What is the expected behavior?

In the CodePen, the popper should incorrectly be positioned if the update was sync. But because it’s not, the last transform line is what Popper knows about, not the first one.

Any other comments?

The asynchronous popper.update() can cause some issues if the next line of code assumes the popper’s position has been updated. The onUpdate() callback can’t really be used depending on the code structure.

I’ve been able to remedy this for a while with setTimeout() defer calls (not sure if this is 100% reliable though), but it would be easier just to have a sync update method.

That, or update is sync while scheduleUpdate is async.

Is there a case where this wouldn’t be appropriate?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:27 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
bimbiltucommented, Apr 16, 2018

Hey @FezVrasta im writing a library that uses popper but I cannot assume that the environment my code runs in will support Promises. How do you feel about scheduleUpdate supporting both callbacks and Promises, similar to Vue’s $nextTick. The code could look like:

function scheduleUpdate(cb) {
  requestAnimationFrame(() => this.debouncedUpdate(cb || () => {}));
  if (!cb && typeof Promise !== 'undefined') {
    return new Promise(resolve => cb = resolve);
  }
}

Id be happy to submit a PR with this code and tests to along with it

1reaction
FezVrastacommented, Dec 8, 2017

Wow cool, good to know.

I think we can plan this change in the next major version, along with a promise-based API for scheduleUpdate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

make Popper#update sync + make scheduleUpdate return ...
I think we can plan this change in the next major version, along with a promise-based API for scheduleUpdate .
Read more >
react-popper: re-position using scheduleUpdate
When onDateRangeBtnClick is called after the button was clicked, I want to re-position the Popper element by calling scheduleUpdate method, but ...
Read more >
Promise - JavaScript - MDN Web Docs
Creates a new Promise object. The constructor is primarily used to wrap functions that do not already support promises. Static methods. Promise.
Read more >
Migration Guide | Popper
This named import lives under the Popper namespace object: ... is now forceUpdate() (and is sync); scheduleUpdate() is now update() (and returns a...
Read more >
Sync, async, and promises | Cloud Functions for Firebase
Also, you can make sure that the Cloud Functions instance running your function ... When you return a JavaScript promise to a function,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found