Skip to content

Delay page saves for async canvas image resize (BL-16302)#7947

Merged
JohnThomson merged 1 commit into
Version6.4from
BL16302-cover-background-paste
Jun 10, 2026
Merged

Delay page saves for async canvas image resize (BL-16302)#7947
JohnThomson merged 1 commit into
Version6.4from
BL16302-cover-background-paste

Conversation

@andrew-polk

@andrew-polk andrew-polk commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

When adjustContainerAspectRatio waits for a newly changed image to load, it can update canvas geometry after changeImage() returns. That left a window where requestPageContent could save stale width, height, and position data.

Register a requestPageContent delay around that image-load retry, keep the existing paste-image wrapper for the separate async feature-status check, add a focused regression test, and update the C# comment that describes the async save behavior.


This change is Reviewable

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 3 files

Re-trigger cubic

@andrew-polk andrew-polk force-pushed the BL16302-cover-background-paste branch from d94245e to fef22d8 Compare June 5, 2026 20:33
When adjustContainerAspectRatio waits for a newly changed image to load, it can update canvas geometry after changeImage() returns. That left a window where requestPageContent could save stale width, height, and position data.

Register a requestPageContent delay around that image-load retry, keep the existing paste-image wrapper for the separate async feature-status check, and update the C# comment that describes the async save behavior.
@andrew-polk andrew-polk force-pushed the BL16302-cover-background-paste branch from fef22d8 to 7a298ca Compare June 10, 2026 17:55
@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a save-race window where adjustContainerAspectRatio could update canvas geometry (width/height/position) asynchronously — after the browser loads a newly changed image — while a requestPageContent save was already in flight with the old values. The fix extracts the async retry into waitForImageAndAdjustContainerAspectRatio, which registers a requestPageContent delay before yielding control and removes it in a try/finally after the geometry updates complete.

  • waitForImageAndAdjustContainerAspectRatio uses an adjustmentResumed flag to guarantee the delay is added once and removed exactly once, whether the load event or the 100 ms fallback timeout fires first.
  • The existing wrapWithRequestPageContentDelay on the paste-new-element branch is preserved, since it covers a separate async feature-status check that precedes any element creation — the two guards are designed to overlap with no uncovered window.
  • EditingModel.cs comments are updated to reflect that delay registration is now spread across multiple sites rather than a single wrapper.

Important Files Changed

Filename Overview
src/BloomBrowserUI/bookEdit/js/CanvasElementManager.ts Extracts the async image-load retry into waitForImageAndAdjustContainerAspectRatio, which now registers addRequestPageContentDelay before yielding and removes it in a try/finally after resuming. The adjustmentResumed flag correctly prevents double execution when both the timeout and load event fire. The constant delay ID works correctly because the activeDelays array supports duplicate entries. The video loadedmetadata path at ~line 2856 is left without equivalent delay protection (pre-existing, noted in comment).
src/BloomExe/Edit/EditingModel.cs Comment-only update to UpdateImageInBrowser: generalises the description from the single wrapWithRequestPageContentDelay wrapper to the broader 'code registers requestPageContent delays' pattern, accurately reflecting the new multi-site delay registration.

Comments Outside Diff (1)

  1. src/BloomBrowserUI/bookEdit/js/CanvasElementManager.ts, line 2852-2861 (link)

    P2 Video async path still unguarded

    The video loadedmetadata branch takes the same async deferred-geometry path that this PR fixes for images — it registers a listener and returns, meaning any save that fires before loadedmetadata would capture stale geometry. The comment here acknowledges the path is untested and "dimensions seem to always be available," but if they ever aren't, the same race applies. Since the image and video paths share the same "return early, fix later" structure, it would be worth wrapping the video listener with the same addRequestPageContentDelay / removeRequestPageContentDelay bookkeeping — or at minimum adding a TODO comment noting the gap.

Reviews (1): Last reviewed commit: "Delay page saves for async canvas image ..." | Re-trigger Greptile

@JohnThomson JohnThomson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@JohnThomson reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on andrew-polk).

@JohnThomson JohnThomson merged commit faa1a71 into Version6.4 Jun 10, 2026
1 check passed
@JohnThomson JohnThomson deleted the BL16302-cover-background-paste branch June 10, 2026 18:00
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