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

debounced updateWindow #469

Conversation

Jaspreet-singh-1032
Copy link
Contributor

fixes #461

I also linked this with Kolibri and tested this out, and It seems to be working fine for me.

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical and brittle code paths are covered by unit tests
  • The change has been added to the changelog

Reviewer guidance

  • Is the code clean and well-commented?
  • Are there tests for this change?
  • Are all UI components LTR and RTL compliant (if applicable)?
  • Add other things to check for here

Comments

@@ -1,5 +1,6 @@
import './composition-api'; //Due to @vue/composition-api shortcomings, add plugin prior to use in kolibri, studio and tests
import { onMounted, onUnmounted, ref } from '@vue/composition-api';
import debounce from 'lodash/debounce';
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI, requestAnimationFrame might be appropriate here because it implements a dynamic throttle. The old responsive window mixin used the frame-throttle wrapper library for this:

import { throttle } from 'frame-throttle';

const windowResizeHandler = throttle(() => {
const metrics = windowMetrics();
windowListeners.forEach(cb => cb(metrics));
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @indirectlylit, Thanks for your review. Just to confirm, do I need to implement it similar to how it is implemented in KResponsiveWindowMixin.js using throttle?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @Jaspreet-singh-1032 - that's for you (and @MisRob) to decide. This is a very minor note and should not block the PR.

That said if you're interested, some links:

Personally, I prefer using this form of throttling for anything related to fluid UI changes because the system can choose an appropriate refresh rate rather than hard-coding a somewhat arbitrary delay period.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, @indirectlylit, I was previously unaware of this function. I will read about it and If it is a better option then I will definitely use it here.

Copy link
Member

Choose a reason for hiding this comment

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

For most browsers this will use requestAnimationFrame, which will invoke the callback just before the next repaint - which means that it should not be the cause of a reflow by reading the inner width and height of the window (which is a strong part of the motivation for this issue), so I do think this is a good change to use here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @rtibbles, I read some blogs about requestAnimationFrame and I also think this is a better option to use here.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @indirectlylit, that's a good idea

Copy link
Member

@akolson akolson left a comment

Choose a reason for hiding this comment

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

Hi @Jaspreet-singh-1032, with exception build errors that I think are resolvable(Some linting issues at the very least), the changes made, make sense me. (cc @MisRob on the build failures )

@MisRob
Copy link
Member

MisRob commented Oct 16, 2023

I'll push update that will resolve the changelog check after all remaining checks are working and the PR is approved (@akolson this will be done by reviewers eventually for majority of PRs from our contributors, I will follow-up soon)

@MisRob
Copy link
Member

MisRob commented Oct 17, 2023

@akolson It's not very clear to me if your comment is meant to be approval? Could you please mark it if that's the case? I will then complete the changelog.

@akolson
Copy link
Member

akolson commented Oct 17, 2023

Hi @MisRob! My comment was meant to specifically address the build failure. I see these have been addressed(or to be addressed). I am more confident approving it now. Thanks

Copy link
Member

@akolson akolson left a comment

Choose a reason for hiding this comment

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

LGTM!

@MisRob
Copy link
Member

MisRob commented Oct 17, 2023

Okay @akolson, thank you. Changelog is updated.

@MisRob
Copy link
Member

MisRob commented Oct 17, 2023

Checks should be okay now. Would recommend Kolibri QA pass as part of review. It's up to you how you want to proceed.

@MisRob
Copy link
Member

MisRob commented Oct 19, 2023

Seems all is done here so merging

@MisRob MisRob merged commit 6aab0a6 into learningequality:main Oct 19, 2023
8 checks passed
Copy link
Member

Choose a reason for hiding this comment

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

@Jaspreet-singh-1032 One of my colleagues noticed an issue with using setTimeout after we merged it, so I opened a follow-up #480. You don't need to work on it, of course! It's rather FYI in case you'd find the note interesting. I didn't realize that either.

@MisRob MisRob mentioned this pull request Feb 29, 2024
8 tasks
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.

Optimize useKWindowDimensions performance
5 participants