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

try fixing intermittent narrower window #43

Merged
merged 1 commit into from
Apr 3, 2024
Merged

try fixing intermittent narrower window #43

merged 1 commit into from
Apr 3, 2024

Conversation

eagleoflqj
Copy link
Member

To reproduce it, apply this patch on current branch, which forces to render based on sizes calculated last time.

diff --git a/page/ux.ts b/page/ux.ts
index f34708b..4b16fa1 100644
--- a/page/ux.ts
+++ b/page/ux.ts
@@ -32,10 +32,12 @@ export function resize (dx: number, dy: number, dragging: boolean) {
   adaptWindowSize()
   if (!dragging) {
     // Sometimes getBoundingClientRect is called when the element is not fully rendered.
-    window.requestAnimationFrame(adaptWindowSize)
+    // window.requestAnimationFrame(adaptWindowSize)
   }
 }
 
+let last = {}
+
 function getBoundingRectWithShadow (element: Element): ShadowBox {
   const rect = element.getBoundingClientRect()
   const elementXHi = rect.x + rect.width
@@ -62,7 +64,8 @@ function getBoundingRectWithShadow (element: Element): ShadowBox {
   // rect.height and rect.width will cover the whole panel and its shadow.
   rect.width = xHi
   rect.height = yHi
-  return {
+  const now = last
+  last = {
     shadowTop: rect.y,
     shadowRight: xHi - elementXHi,
     shadowBottom: yHi - elementYHi,
@@ -70,6 +73,7 @@ function getBoundingRectWithShadow (element: Element): ShadowBox {
     fullWidth: xHi,
     fullHeight: yHi
   }
+  return now
 }
 
 document.addEventListener('mousedown', e => {

In Pinyin, type a s, you should see
narrow
every time.
Then uncomment window.requestAnimationFrame(adaptWindowSize), you should see
normal
every time.

@eagleoflqj eagleoflqj requested a review from ksqsf April 3, 2024 02:10
Copy link
Member

@ksqsf ksqsf left a comment

Choose a reason for hiding this comment

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

Can confirm requestAnimationFrame works. LGTM

@ksqsf ksqsf merged commit 8353719 into master Apr 3, 2024
3 checks passed
@ksqsf ksqsf deleted the narrow branch April 3, 2024 06:27
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.

2 participants