-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix: Add missing await to fromDataBuffer call in font upload #73755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Fix: Add missing await to fromDataBuffer call in font upload #73755
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @GovardhaneNitin. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @GovardhaneNitin! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds the missing await keyword when calling the async fromDataBuffer method during font upload, and updates the TypeScript type definition to reflect that fromDataBuffer returns a Promise<void>. The change aims to fix a race condition that caused "Invalid font data in ArrayBuffer" errors when uploading TTF fonts.
- Updated the return type of
fromDataBufferin the type definition fromvoidtoPromise<void> - Added
awaitwhen callingfontObj.fromDataBuffer()in the font metadata extraction function
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/global-styles-ui/src/font-library-modal/lib/lib-font.browser.d.ts | Updates the TypeScript type definition to correctly indicate that fromDataBuffer returns a Promise |
| packages/global-styles-ui/src/font-library-modal/upload-fonts.tsx | Adds await to the fromDataBuffer call to properly wait for font parsing to complete |
Comments suppressed due to low confidence (1)
packages/global-styles-ui/src/font-library-modal/upload-fonts.tsx:159
- Adding
awaithere creates a race condition. ThefromDataBuffermethod callsthis.onload(evt)at the end of its execution (line 847 in lib-font.browser.js). By awaiting this call,fromDataBuffercompletes before theonloadhandler is set up on line 158 below. This means theonloadcallback is invoked whenfontObj.onloadis still undefined, so the Promise on lines 157-159 will never resolve, causing the code to hang.
The solution is to set up the onload handler BEFORE calling fromDataBuffer, or remove the redundant Promise wait on lines 157-159 since fromDataBuffer is now properly awaited and the font data will be available after line 155 completes.
await fontObj.fromDataBuffer( buffer, fontFile.name );
// Assuming that fromDataBuffer triggers onload event and returning a Promise
const onloadEvent: { detail: { font: any } } = await new Promise(
( resolve ) => ( fontObj.onload = resolve )
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The fromDataBuffer method is async but was being called without await, causing a race condition that resulted in 'Invalid font data in ArrayBuffer' errors when uploading TTF fonts. This fix ensures the font parsing completes before proceeding with metadata extraction, resolving the issue where TTF fonts would fail to upload while WOFF2 files worked correctly. Fixes WordPress#72265
2e78923 to
324d5a2
Compare
The fromDataBuffer method is async but was being called without await, causing a race condition that resulted in 'Invalid font data in ArrayBuffer' errors when uploading TTF fonts.
This fix ensures the font parsing completes before proceeding with metadata extraction, resolving the issue where TTF fonts would fail to upload while WOFF2 files worked correctly.
Fixes #72265