Social: Fix SIG preview infinite spinner when default image is deleted#47945
Social: Fix SIG preview infinite spinner when default image is deleted#47945
Conversation
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
…image # Conflicts: # projects/packages/publicize/_inc/components/generated-image-preview/index.tsx # projects/packages/publicize/_inc/components/generated-image-preview/test/index.test.js
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryCoverage changed in 6 files. Only the first 5 are listed here.
Full summary · PHP report · JS report Coverage check overridden by
Covered by non-unit tests
|
There was a problem hiding this comment.
Pull request overview
Fixes the Social Image Generator (SIG) template preview getting stuck in an infinite spinner when the configured default background image attachment has been deleted, by distinguishing “still resolving” vs “resolved but missing” across hooks/components and adding resilience around preview generation.
Changes:
- Update SIG preview media resolution to treat missing (deleted) attachments as
nullrather than “still loading”, and adjustcalculateImageUrl()accordingly. - Harden
useSigPreviewtoken generation with abortable requests and error handling; expand unit tests to cover abort + failure paths. - Extend
useMediaDetailsto expose anisNotFoundsignal and update dependent UI/tests to hide/fallback when the default image no longer exists.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/packages/publicize/changelog/fix-social-424-sig-preview-deleted-default-image | Adds changelog fragment for the SIG infinite spinner fix. |
| projects/packages/publicize/_inc/hooks/use-sig-preview/utils.ts | Distinguishes undefined (loading) vs null (missing) media in calculateImageUrl. |
| projects/packages/publicize/_inc/hooks/use-sig-preview/test/utils.test.js | Adds coverage for “resolved but missing attachment” returning null. |
| projects/packages/publicize/_inc/hooks/use-sig-preview/test/index.test.js | Updates expectations and adds tests for abort + apiFetch rejection + missing attachment behavior. |
| projects/packages/publicize/_inc/hooks/use-sig-preview/index.ts | Adds hasFinishedResolution checks for attachments; makes token generation abortable + resilient to failures. |
| projects/packages/publicize/_inc/hooks/use-media-details/types.ts | Makes metaData / mediaData optional on the MediaDetails type. |
| projects/packages/publicize/_inc/hooks/use-media-details/index.js | Uses hasFinishedResolution and returns [details, isNotFound] to detect deleted attachments. |
| projects/packages/publicize/_inc/hooks/use-connection-preview-data/test/index.test.ts | Updates mocks for the useMediaDetails return shape in affected tests. |
| projects/packages/publicize/_inc/hooks/use-connection-media-validation/test/index.test.ts | Updates mocks for the useMediaDetails return shape. |
| projects/packages/publicize/_inc/components/unified-modal/edit-template/test/sidebar.test.tsx | Adds tests for fallback from deleted default image and hiding the “Default Image” option. |
| projects/packages/publicize/_inc/components/unified-modal/edit-template/background-image-picker.tsx | Hides default option when deleted; falls back from default to none. |
| projects/packages/publicize/_inc/components/social-image-generator/template-picker/modal/test/index.test.js | Updates hook mocking and adds test for clearing image when attachment is missing. |
| projects/packages/publicize/_inc/components/social-image-generator/template-picker/modal/index.js | Clears selected image when useMediaDetails reports attachment not found. |
Fixes SOCIAL-424
Proposed changes
When the global Social Image Generator (SIG) default background image is deleted from the media library, the SIG template preview shows an infinite spinner. This happens because
getEntityRecordfor a deleted attachment never resolves, causingcalculateImageUrl()to permanently returnFEATURED_IMAGE_STILL_LOADING.This PR fixes the issue by checking
hasFinishedResolutionto distinguish "still loading" from "attachment doesn't exist" across all affected code paths:Core fixes
useSigPreviewhook — ThegetMediacallback now checkshasFinishedResolutionso deleted attachments resolve tonullinstead of staying stuck asFEATURED_IMAGE_STILL_LOADING. Also addedtry/catchon theapiFetchcall (previously an API error would also cause an infinite spinner), and anAbortControllerto cancel in-flight requests on effect cleanup.calculateImageUrl— Now distinguishesundefined(still loading) fromnull(resolved but missing) when checking the media entity.useMediaDetailshook — AddedhasFinishedResolutioncheck and exposes anisNotFoundflag so consumers can detect deleted attachments.UI fixes
GeneratedImagePreview— AddedonErrorhandler on the<img>tag so a broken image URL stops the spinner instead of spinning forever.BackgroundImagePicker(post editor) — Hides the "Default Image" menu option when the default image doesn't exist. Automatically falls back to'none'ifimageTypewas set to'default'for a deleted image.TemplatePickerModal(admin settings page) — Clears the selected image when the attachment is detected as not found, showing the "Choose Image" button instead of a spinner.Cleanup
generatedImageUrlRefthat was no longer used after theAbortControllerrefactor.MediaDetailstype fields optional to match the actual runtime behavior (the hook can return{}when no media exists).Other information
Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Prerequisites: A WordPress site with Jetpack Social plan and SIG enabled.
Scenario 1: Deleted default image — post editor
Scenario 2: Deleted default image — setting featured image first
Scenario 3: Deleted default image — admin settings page
Scenario 4: Normal flow (no regression)
Scenario 5: API failure resilience
generate-token