Skip to content

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Sep 15, 2025

To do:

  • TypeScript build
  • Static language data compilation

Proposed changes:

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?

Testing instructions:

  • Go to '..'

This allows import() to be used in the build. Before, it would error
with:

> The target environment doesn't support 'import()' so it's not possible
> to use external type 'import'
Copy link
Contributor

github-actions bot commented Sep 15, 2025

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!


Mu Wpcom plugin:

  • Next scheduled release: WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2)

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


Wpcomsh plugin:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2)

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

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Sep 15, 2025
@gziolo
Copy link
Member

gziolo commented Sep 17, 2025

Excellent progress! 🎉

How can I test it? What's left to do?

I see that it's implemented as a standalone block. What is your latest opinion about having it as a new block vs enhancing the Code (core/code) block?

@sirreal
Copy link
Member Author

sirreal commented Sep 17, 2025

How can I test it?

I'll prepare an easy way to test this soon on WordPress.com. There's also the Jetpack Beta Tester plugin for testing on WordPress.com WP Cloud sites.

What's left to do?

I just got it building and working, so I need to review things myself and make sure it's finished and all working correctly 🙂

@sirreal sirreal added the [Type] Feature Development of a new feature label Sep 17, 2025
@sirreal sirreal requested a review from Copilot September 17, 2025 14:22
Copy link
Contributor

@Copilot 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 a new experimental code block feature to the jetpack-mu-wpcom package. The implementation includes a full-featured code editor with syntax highlighting, language detection, and various display options.

Key changes:

  • New code block implementation: Introduces an a8c/code block with CodeMirror-based editing capabilities, syntax highlighting, and language auto-detection
  • Enhanced build configuration: Updates webpack configuration to support the new block's modules and adds Lezer grammar processing for custom language parsers
  • Feature integration: Integrates the code block into the main plugin loader and adds changelog entries across related projects

Reviewed Changes

Copilot reviewed 31 out of 33 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
projects/packages/jetpack-mu-wpcom/webpack.config.modules.js Adds new entry points for code block modules and Lezer grammar processing
projects/packages/jetpack-mu-wpcom/webpack.config.js Adds code block definition entry point and ES2020 target configuration
projects/packages/jetpack-mu-wpcom/src/features/wpcom-blocks/code/ Complete code block implementation with editor, parser, styling, and PHP backend
projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php Integrates code block into main feature loader
projects/packages/jetpack-mu-wpcom/package.json Adds CodeMirror and Lezer dependencies
projects/packages/jetpack-mu-wpcom/lezer-loader.js Custom webpack loader for processing Lezer grammar files
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

const fromBase64 =
typeof Uint8Array.fromBase64 === 'function'
? ( toDecode: string ): string => {
// biome-ignore lint/style/noNonNullAssertion: This is checked aboid and should narrow here.
Copy link
Preview

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

There's a typo in the comment: 'aboid' should be 'above'.

Copilot uses AI. Check for mistakes.

const toBase64 =
typeof Uint8Array.prototype.toBase64 === 'function'
? ( toEncode: string ): string => {
// biome-ignore lint/style/noNonNullAssertion: This is checked aboid and should narrow here.
Copy link
Preview

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

There's a typo in the comment: 'aboid' should be 'above'.

Copilot uses AI. Check for mistakes.

// <code>### text ###</code>.
if (
! $this->next_token() ||
! $this->get_token_type() === '#text'
Copy link
Preview

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

The negation operator has incorrect precedence. This should be $this->get_token_type() !== '#text' to properly check if the token type is not equal to '#text'.

Suggested change
! $this->get_token_type() === '#text'
$this->get_token_type() !== '#text'

Copilot uses AI. Check for mistakes.

$code_string = $this->get_modifiable_text();
if (
! $this->next_token() ||
! $this->get_tag() === 'CODE' ||
Copy link
Preview

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

The negation operators have incorrect precedence. These should be $this->get_tag() !== 'CODE' and ! $this->is_tag_closer() respectively to properly check the conditions.

Suggested change
! $this->get_tag() === 'CODE' ||
$this->get_tag() !== 'CODE' ||

Copilot uses AI. Check for mistakes.

const language = getLanguage( file )!;

// Grab the last segment of the file name. Try to handle different path separators.
const filename = file.name.split( /\\\// ).at( -1 ) ?? '';
Copy link
Preview

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

The regex pattern /\\\// is incorrect for splitting on path separators. It should be /[\\/]/ to match either backslash or forward slash characters.

Suggested change
const filename = file.name.split( /\\\// ).at( -1 ) ?? '';
const filename = file.name.split( /[\\/]/ ).at( -1 ) ?? '';

Copilot uses AI. Check for mistakes.

<code
className={
language
? `language-${ language.toLowerCase().replace( ' \t\n\r\f', '_' ) }`
Copy link
Preview

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

The replace method is being called with a string instead of a regex. It should be .replace(/[ \t\n\r\f]/g, '_') to replace all whitespace characters with underscores.

Suggested change
? `language-${ language.toLowerCase().replace( ' \t\n\r\f', '_' ) }`
? `language-${ language.toLowerCase().replace(/[ \t\n\r\f]/g, '_' ) }`

Copilot uses AI. Check for mistakes.

const textColorProperties: CSSProperties = {};
if ( attributes.textColor ) {
backgroundProperties[ '--colorText' ] = `var( --wp--preset--color--${ attributes.textColor } )`;
} else if ( attributes.style?.color?.background ) {
Copy link
Preview

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

The condition checks for background property but then sets the text color from text property. This should be attributes.style?.color?.text in the condition.

Suggested change
} else if ( attributes.style?.color?.background ) {
} else if ( attributes.style?.color?.text ) {

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[mu wpcom Feature] Wpcom Blocks [Package] Jetpack mu wpcom WordPress.com Features [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Wpcomsh [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Type] Feature Development of a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants