Skip to content

Conversation

@CGastrell
Copy link
Contributor

Part of FORMS-478

Proposed changes:

When WP emoji replacement scripts swaps our flag characters the interactivity API fails to bind with data-wp-text and the flags don't update.

Summary of the change:

  1. PHP changes (class-contact-form-field.php):
    - Replaced data-wp-text with data-wp-watch="callbacks.updateSelectedFlag/updateOptionFlag"
    - Added ​ (zero-width space) placeholder to ensure a text node exists
    - Kept wp-exclude-emoji class as fallback for initial page parse
  2. JS changes (view.js):
    - Added updateSelectedFlag and updateOptionFlag callbacks
    - These callbacks modify firstChild.data instead of textContent
    - Since wp-emoji's MutationObserver only watches childList (not characterData), modifying .data doesn't trigger emoji conversion

The key insight: wp-emoji's MutationObserver uses: .observe(document.body, { childList: true, subtree: true })

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

No

Testing instructions:

Before the fix:

  • Emoji characters → converted to SVG tags by wp-emoji
  • This broke the dropdown because data-wp-text would keep resetting to text, causing a conflict

After the fix:

  • Emoji characters stay as emoji characters (no SVG conversion)
  • The MutationObserver doesn't trigger because we modify .data instead of replacing textContent
  • The dropdown works correctly

NOTE: in order to see the swap on local envs, you can use this on startup:

  add_action( 'wp_head', function() {
	// Inject script BEFORE the emoji detection (priority 7)
	// This sets fake "no support" values in sessionStorage
	?>
	<script>
	try {
	  sessionStorage.setItem('wpEmojiSettingsSupports', JSON.stringify({
		timestamp: Date.now(),
		supportTests: { flag: false, emoji: false }
	  }));
	} catch(e) {}
	</script>
	<?php
  }, 6 );
 
  // Force load the emoji scripts even if browser supports emojis
  add_action( 'wp_enqueue_scripts', function() {
	// Enqueue twemoji and wp-emoji scripts
	wp_enqueue_script(
	  'twemoji',
	  includes_url( 'js/twemoji.js' ),
	  array(),
	  false,
	  array( 'in_footer' => false )
	);
	wp_enqueue_script(
	  'wp-emoji',
	  includes_url( 'js/wp-emoji.js' ),
	  array( 'twemoji' ),
	  false,
	  array( 'in_footer' => false )
	);
  }, 100 );

@CGastrell CGastrell self-assigned this Jan 7, 2026
Copilot AI review requested due to automatic review settings January 7, 2026 20:33
@CGastrell CGastrell added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Package] Forms Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR labels Jan 7, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/forms-phone-dropdown-flags-handling branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/forms-phone-dropdown-flags-handling

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link
Contributor

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 fixes an issue where WordPress emoji replacement scripts would convert flag emoji characters to SVG images, breaking the phone field country selector dropdown in forms. The fix changes how flag updates are handled by using the Interactivity API's data-wp-watch with callbacks that directly modify text node data instead of textContent, thereby avoiding triggering wp-emoji's MutationObserver.

Key Changes:

  • Replaced data-wp-text with data-wp-watch callbacks for flag rendering to bypass wp-emoji interference
  • Added zero-width space (&#8203;) placeholder to ensure text nodes exist for manipulation
  • Implemented two new callbacks (updateSelectedFlag and updateOptionFlag) that modify firstChild.data instead of textContent

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
projects/packages/forms/src/modules/field-phone/view.js Added two new callbacks (updateSelectedFlag and updateOptionFlag) that update flag display by modifying text node data to avoid triggering wp-emoji's MutationObserver
projects/packages/forms/src/contact-form/class-contact-form-field.php Updated phone field combobox HTML to use data-wp-watch with callbacks instead of data-wp-text, added wp-exclude-emoji class and zero-width space placeholder for flag elements
projects/packages/forms/changelog/fix-forms-phone-dropdown-flags-handling Added changelog entry documenting the fix for phone combobox flag handling

@jp-launch-control
Copy link

jp-launch-control bot commented Jan 7, 2026

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/modules/field-phone/view.js 116/142 (81.69%) 1.54% 0 💚

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

Copy link
Contributor

@dhasilva dhasilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tests well

@CGastrell CGastrell merged commit f07d85f into trunk Jan 8, 2026
70 checks passed
@CGastrell CGastrell deleted the fix/forms-phone-dropdown-flags-handling branch January 8, 2026 12:45
@github-actions github-actions bot added this to the jetpack/15.5 milestone Jan 8, 2026
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR [Feature] Contact Form [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests [Type] Bug When a feature is broken and / or not performing as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants