fix: prevent Design Library from showing blank on fetch errors - #3732
fix: prevent Design Library from showing blank on fetch errors#3732bfintal wants to merge 1 commit into
Conversation
Guard against undefined library responses and stop caching failed CDN fetches so the Design Library can load designs or surface errors instead of crashing. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
📝 WalkthroughWalkthroughDesign-library fetching now centralizes client caching and error handling, avoids persisting failed server responses, retries invalid cached data, and reports sidebar loading failures through component state. ChangesDesign library reliability
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🤖 Pull request artifacts
|
|
Size Change: +265 B (+0.01%) Total Size: 2.63 MB 📦 View Changed
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/design-library/index.js`:
- Around line 21-36: Update the fetch logic around needsFetch and apiFetch so
failed or undefined responses remain identifiable as errors rather than being
normalized to an empty object. Include hasLibraryError( designLibrary[ type ] )
in the needsFetch condition so cached error responses can be retried, and
preserve the raw invalid response as the stored error sentinel while retaining
normal successful-response handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d12147f8-bb92-43f2-8a24-8fd689497b64
📒 Files selected for processing (3)
src/design-library/index.jssrc/design-library/init.phpsrc/lazy-components/design-library/index.js
| const needsFetch = ( type === 'patterns' || type === 'pages' ) && ! designLibrary[ type ] | ||
|
|
||
| if ( needsFetch ) { | ||
| const results = await apiFetch( { | ||
| path: `/stackable/v2/design_library/${ type }${ forceReset ? '/reset' : '' }`, | ||
| method: 'GET', | ||
| } ) | ||
| const designsPerType = results | ||
| } ) || {} | ||
|
|
||
| designLibrary[ type ] = designsPerType | ||
| designLibrary[ type ] = results | ||
|
|
||
| if ( type === 'patterns' ) { | ||
| designs = designsPerType[ LATEST_API_VERSION ] ?? {} | ||
| } else { | ||
| pages = designsPerType[ LATEST_API_VERSION ] ?? {} | ||
| if ( hasLibraryError( results ) ) { | ||
| if ( type === 'patterns' ) { | ||
| designs = {} | ||
| } | ||
| } else if ( type === 'patterns' ) { | ||
| designs = results[ LATEST_API_VERSION ] ?? {} |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Do not cache or normalize failed client responses as an empty library.
Line 27 turns an undefined API result into {}, which passes getDesigns validation and renders an empty library. Also, after an error response is stored, Line 21 prevents later calls from retrying because the error object is truthy. Preserve invalid responses as an error sentinel and include hasLibraryError( designLibrary[ type ] ) in needsFetch.
Proposed fix
- const needsFetch = ( type === 'patterns' || type === 'pages' ) && ! designLibrary[ type ]
+ const needsFetch = ( type === 'patterns' || type === 'pages' ) &&
+ ( ! designLibrary[ type ] || hasLibraryError( designLibrary[ type ] ) )
if ( needsFetch ) {
- const results = await apiFetch( {
+ const response = await apiFetch( {
path: `/stackable/v2/design_library/${ type }${ forceReset ? '/reset' : '' }`,
method: 'GET',
- } ) || {}
+ } )
+ const results = response && typeof response === 'object'
+ ? response
+ : { content_error: { message: 'Failed to load design library.' } }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const needsFetch = ( type === 'patterns' || type === 'pages' ) && ! designLibrary[ type ] | |
| if ( needsFetch ) { | |
| const results = await apiFetch( { | |
| path: `/stackable/v2/design_library/${ type }${ forceReset ? '/reset' : '' }`, | |
| method: 'GET', | |
| } ) | |
| const designsPerType = results | |
| } ) || {} | |
| designLibrary[ type ] = designsPerType | |
| designLibrary[ type ] = results | |
| if ( type === 'patterns' ) { | |
| designs = designsPerType[ LATEST_API_VERSION ] ?? {} | |
| } else { | |
| pages = designsPerType[ LATEST_API_VERSION ] ?? {} | |
| if ( hasLibraryError( results ) ) { | |
| if ( type === 'patterns' ) { | |
| designs = {} | |
| } | |
| } else if ( type === 'patterns' ) { | |
| designs = results[ LATEST_API_VERSION ] ?? {} | |
| const needsFetch = ( type === 'patterns' || type === 'pages' ) && | |
| ( ! designLibrary[ type ] || hasLibraryError( designLibrary[ type ] ) ) | |
| if ( needsFetch ) { | |
| const response = await apiFetch( { | |
| path: `/stackable/v2/design_library/${ type }${ forceReset ? '/reset' : '' }`, | |
| method: 'GET', | |
| } ) | |
| const results = response && typeof response === 'object' | |
| ? response | |
| : { content_error: { message: 'Failed to load design library.' } } | |
| designLibrary[ type ] = results | |
| if ( hasLibraryError( results ) ) { | |
| if ( type === 'patterns' ) { | |
| designs = {} | |
| } | |
| } else if ( type === 'patterns' ) { | |
| designs = results[ LATEST_API_VERSION ] ?? {} |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/design-library/index.js` around lines 21 - 36, Update the fetch logic
around needsFetch and apiFetch so failed or undefined responses remain
identifiable as errors rather than being normalized to an empty object. Include
hasLibraryError( designLibrary[ type ] ) in the needsFetch condition so cached
error responses can be retried, and preserve the raw invalid response as the
stored error sentinel while retaining normal successful-response handling.
|
Hello @bfintal Thank you for noticing my message, and I apologize again for the off-topic post. Since, as you surely remember, I deal with translations, have you already noticed this issues report #3607 of mine from October 1, 2025 regarding the strings in the javascript chunk files not showing up as translated? Thanks again. |
Summary
wp_remote_get_errorand left the library blankTest plan
Cannot read properties of undefined (reading 'wp_remote_get_error')console errorMade with Cursor
Summary by CodeRabbit