monkeytype/frontend
Seif Soliman 10aa8941e1
fix(caret): prevent misalignment on initial load and resize (@byseif21, @NadAlaba) (#6641)
### Description

This PR fixes two related caret positioning issues that occurred
**before any user input**:

* **Resize Bug**:
Resizing the browser immediately after a page refresh caused the caret
to appear misaligned. The position only corrected itself after the user
typed the first character.

* **Navigation Bug**:
Navigating away from the test page and back (especially after a refresh)
caused the caret to initially render in the wrong position, then animate
into place.

---

### Solution

* Refactor `Caret.updatePosition()` to use `getComputedStyle` for
width/height instead of `getBoundingClientRect()` and `offsetHeight`
makes caret positioning more accurate.
* Redundant calls to Caret.updatePosition() have been removed from the
resize handler, relying instead on the more
 comprehensive caret re-initialization.


These changes resolve caret alignment and animation issues after
loading, resizing, or navigating, including in tape mode.

 
---

> ~~Replaced early calls to `Caret.updatePosition()` with `Caret.show()`
when no input has been entered yet.~~

>  ~~`Caret.show()` ensures the caret is:~~

> ~~* Visible~~
>  ~~* Properly initialized~~
>  ~~* Animated via `startAnimation()`~~
> ~~* Positioned correctly via internal `updatePosition()` call~~

> ~~Once the caret is initialized (i.e., after first input), we continue
using `updatePosition()` directly for subsequent updates.~~
>  

---

Closes #6639
2025-06-25 15:27:49 +02:00
..
__tests__ impr(lazy mode): support replacing 2 characters with one 2025-06-22 10:49:17 +02:00
docker fix: local development using docker not working with pnpm (@fehmer) (#6401) 2025-03-26 13:11:02 +01:00
scripts refactor: move languages to contracts (@fehmer) (#6497) 2025-05-07 14:02:27 +02:00
src fix(caret): prevent misalignment on initial load and resize (@byseif21, @NadAlaba) (#6641) 2025-06-25 15:27:49 +02:00
static impr(quotes): add Russian quotes (@WormholeDragon) (#6632) 2025-06-25 15:14:04 +02:00
.eslintrc.cjs chore: add eslint compat plugin (@fehmer) (#6542) 2025-05-12 16:52:01 +02:00
.firebaserc_example
.oxlintrc.json chore: update plugins overrides 2025-06-14 15:33:52 +02:00
firebase.json
gulpfile.js chore: add oxlint (@miodec) (#6455) 2025-04-16 17:18:50 +02:00
knip.json
package.json chore: bump oxlint version 2025-06-14 14:43:05 +02:00
tsconfig.json
vite.config.dev.js chore: add oxlint (@miodec) (#6455) 2025-04-16 17:18:50 +02:00
vite.config.js chore: add sentry 2025-04-29 17:36:23 +02:00
vite.config.prod.js chore: try to use auto commit detection again 2025-05-03 12:02:51 +02:00
vitest.config.js refactor: move funboxes to a shared package (@miodec) (#6063) 2024-12-04 16:11:07 +01:00