fix(ui): delay initial fetch until browser is idle

Right now the very fist fetch() happens right after Fetcher instance is created, which might be while a lot of other components are still being created. Wrap it inside requestAnimationFrame so it's executed once the browser is (fairly) idle
This commit is contained in:
Łukasz Mierzwa
2019-05-04 22:48:40 +01:00
parent 348e33f706
commit c298a6cd69
2 changed files with 5 additions and 1 deletions

View File

@@ -54,7 +54,8 @@ const Fetcher = observer(
};
componentDidMount() {
this.fetchIfIdle();
// start first fetch once the browser is done doing busy loading
window.requestAnimationFrame(this.fetchIfIdle);
this.timer = setInterval(this.timerTick, 1000);
}

View File

@@ -29,9 +29,12 @@ beforeEach(() => {
settingsStore = new Settings();
settingsStore.fetchConfig.config.interval = 30;
jest.spyOn(window, "requestAnimationFrame").mockImplementation(cb => cb());
});
afterEach(() => {
window.requestAnimationFrame.mockRestore();
jest.clearAllTimers();
jest.clearAllMocks();
jest.restoreAllMocks();