Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

perf: Reduce Popper updates when placement don't change #257

Merged
merged 2 commits into from
Dec 12, 2018

Conversation

piecyk
Copy link
Contributor

@piecyk piecyk commented Dec 11, 2018

ScheduleUpdate is called twice per state change, as placement !== this.state.placement is not inside the setState callback, so the this.state is referring to current state and it's calling scheduleUpdate when the callback fires

In the same time in componentDidUpdate we have the

if (prevState.placement !== this.state.placement) {
  this.scheduleUpdate();
}

state placement changed, call the scheduleUpdate

Outcome of this is that on every new state.placement we call two time the scheduleUpdate IMHO it's redundant as scheduleUpdate is called at the same time.

@piecyk
Copy link
Contributor Author

piecyk commented Dec 11, 2018

hmm, looks like this breaks correct position of popper at my internal tooltip implementation...
Need to look closer... will ping with results

@piecyk
Copy link
Contributor Author

piecyk commented Dec 12, 2018

Checkout what was the problem... changing initial state placement value to what we pass in props is not good for poppers with arrow as we set placement to child function after we got first popper data.

After first placement, arrow is added with some margin that's increase popper element height and invalidates it's position.

Current flow,

  1. first render, popper.js is triggered, state.placement = undefined
  2. we got data, data.placement !== state.placement, trigger schedule update
  3. we got data, data.placement === state.placement, done

initial placement on state should stay undefined

@FezVrasta it's ready

@FezVrasta FezVrasta merged commit 9763593 into floating-ui:master Dec 12, 2018
@FezVrasta
Copy link
Member

thanks so much! merged

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

Successfully merging this pull request may close these issues.

2 participants