wilsonpage / fastdom

Eliminates layout thrashing by batching DOM measurement and mutation tasks
6.85k stars 240 forks source link

A little help with fastdom/fastdom-strict #126

Closed tleish closed 3 years ago

tleish commented 3 years ago

I have the following code

//... 
this.element.focus();

When including fastdom-strict, I get the error:

Uncaught Error: Can only get focus during 'measure' phase

So I update the code to:

import fastdom from "fastdom";

//... 

fastdom.measure(() => {
  this.element.focus();
});

And I'm still getting the same error. What am I missing?

tleish commented 3 years ago

Found the problem. fastdom-strict monkey-patches window.fastdom, so you need to have the fastdom singleton in the window scope.

import fastdom from "fastdom";
+ window.fastdom = fastdom;

//... 

fastdom.measure(() => {
  this.element.focus();
});