Stirling-PDF/frontend/src
Ludy be7e79be55
fix(viewer): make initial zoom setup robust and clear timers in ZoomAPIBridge (#4588)
# Description of Changes

**What was changed**
- Reworked the initial zoom `useEffect`:
- Early return when `zoom` is unavailable or initial zoom was already
applied.
  - Extracted an `attemptInitialZoom` function with a single retry path.
- Introduced proper timeout handles (`timer`, `retryTimer`) and added a
cleanup function to clear them on unmount/re-render.
- Expanded the effect dependency array to include `zoomState` to avoid
stale state issues.
- Switched to nullish coalescing for safer defaulting of
`currentZoomLevel` (`zoomState.currentZoomLevel ?? 1.4`).
- Minor logging adjustments to clarify delayed/failed initialization
paths.

**Why the change was made**
- The previous implementation risked leaving dangling timers and could
re-attempt zoom unnecessarily, causing flicker or inconsistent initial
zoom when the viewport wasn’t ready.
- Including `zoomState` in dependencies ensures the component reacts to
state changes correctly and avoids stale reads.
- Cleanup of timers prevents memory leaks and race conditions during
rapid mounts/unmounts or navigation.

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Reece Browne <74901996+reecebrowne@users.noreply.github.com>
2025-10-06 12:24:12 +01:00
..
assets Feature/v2/sign (#4485) 2025-09-26 19:11:03 +01:00
components fix(viewer): make initial zoom setup robust and clear timers in ZoomAPIBridge (#4588) 2025-10-06 12:24:12 +01:00
constants style(frontend): standardize semicolons across TS/JS configs and components (#4525) 2025-09-29 12:55:53 +01:00
contexts Feature/v2/navigate save prompt (#4586) 2025-10-02 20:14:35 +01:00
data Feature/adjust colors contrast tool (#4544) 2025-10-02 17:48:39 +01:00
hooks Feature/adjust colors contrast tool (#4544) 2025-10-02 17:48:39 +01:00
i18n V2: Convert Tool (#3828) 2025-08-01 16:08:04 +01:00
pages shortcuts and config menu (#4530) 2025-10-01 20:22:04 +01:00
services Feature/v2/navigate save prompt (#4586) 2025-10-02 20:14:35 +01:00
styles Created shared component (#4580) 2025-10-02 13:10:13 +01:00
tests style(frontend): standardize semicolons across TS/JS configs and components (#4525) 2025-09-29 12:55:53 +01:00
theme Feature/toasts and error handling (#4496) 2025-09-25 21:03:53 +01:00
tools Feature/adjust colors contrast tool (#4544) 2025-10-02 17:48:39 +01:00
types refactor(types): deduplicate AutomateParameters definition in automation types (#4522) 2025-09-29 12:45:37 +01:00
utils Feature/v2/navigate save prompt (#4586) 2025-10-02 20:14:35 +01:00
App.css Initial react set up 2025-05-09 20:01:09 +01:00
App.tsx shortcuts and config menu (#4530) 2025-10-01 20:22:04 +01:00
global.d.ts Feature/v2/sign (#4485) 2025-09-26 19:11:03 +01:00
i18n.ts path (#4488) 2025-09-24 20:37:51 +01:00
index.css Basic footer structure and Cookie Consent (#4320) 2025-08-29 13:01:46 +00:00
index.tsx path (#4488) 2025-09-24 20:37:51 +01:00
logo.svg Initial react set up 2025-05-09 20:01:09 +01:00
output.css Mantine overhaul 2025-05-15 20:07:33 +01:00
reportWebVitals.js Initial react set up 2025-05-09 20:01:09 +01:00
setupTests.js Initial react set up 2025-05-09 20:01:09 +01:00
setupTests.ts style(frontend): standardize semicolons across TS/JS configs and components (#4525) 2025-09-29 12:55:53 +01:00