WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 6 months ago

#40698 new feature request

The function wp.emoji.parse is available only after another function is run

Reported by: superpoincare Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.4
Component: Emoji Keywords: reporter-feedback
Focuses: javascript Cc:
PR Number:

Description

I wanted to be able to write a custom Javascript to load wp-emoji-release.min.js as soon as possible (say using rel="preload" and/or async) and start using the function wp.emoji.parse as soon as possible (such as via mutation observer).

But what's happening is that for the function to work, it needs to run the load() function defined in wp-emoji.js

twemoji has been defined as window.twemoji inside the load function https://github.com/WordPress/WordPress/blob/master/wp-includes/js/wp-emoji.js#L58

So using wp.emoji.parse needs to wait till load() is run.

This can be seen if you see the minified version which has "g.parse" instead of twemoji.parse.

So using wp.emoji.parse(object) early will just return the object instead of modifying it.

Is it possible to make wp.emoji.parse available as soon as possible? I think this can be done by moving

twemoji = window.twemoji

outside before the function load() is defined.

Change History (1)

#1 @pento
6 months ago

  • Keywords reporter-feedback added

Twemoji needs to be loaded for wp.emoji.parse() to work, hence why load() waits for window.twemoji to be defined before continuing.

Can you give a more clearly defined example of why you need to use parse() earlier than when load() runs?

Note: See TracTickets for help on using tickets.