Skip to content

Conversation

@GovardhaneNitin
Copy link

@GovardhaneNitin GovardhaneNitin commented Dec 4, 2025

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

Copilot AI review requested due to automatic review settings December 4, 2025 12:57
@github-actions
Copy link

github-actions bot commented Dec 4, 2025

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 props-bot label.

Unlinked Accounts

The 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.

Unlinked contributors: GovardhaneNitin.

Co-authored-by: sidharthpandita1 <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: FakhriAz <[email protected]>
Co-authored-by: Robertght <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Dec 4, 2025
@github-actions
Copy link

github-actions bot commented Dec 4, 2025

👋 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.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Feature] Font Library labels Dec 4, 2025
Copy link

Copilot AI left a 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 fromDataBuffer in the type definition from void to Promise<void>
  • Added await when calling fontObj.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 await here creates a race condition. The fromDataBuffer method calls this.onload(evt) at the end of its execution (line 847 in lib-font.browser.js). By awaiting this call, fromDataBuffer completes before the onload handler is set up on line 158 below. This means the onload callback is invoked when fontObj.onload is 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
@GovardhaneNitin GovardhaneNitin force-pushed the fix/font-library-ttf-upload-72265 branch from 2e78923 to 324d5a2 Compare December 4, 2025 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Font Library First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom font upload not working

2 participants