The WordPress coreCoreCore is the set of software required to run WordPress. The Core Development Team builds WordPress. development team builds WordPress! Follow this site for general updates, status reports, and the occasional code debate. There’s lots of ways to contribute:
Found a bugbugA bug is an error or unexpected result. Performance improvements, code optimization, and are considered enhancements, not defects. After feature freeze, only bugs are dealt with, with regressions (adverse changes from the previous version) being the highest priority.?Create a ticket in the bug tracker.
In case you missed the first post on post/page performance, I’d recommend checking it out first before digging into this post, as it helps give greater context into the breadth of work around performance improvements. This post builds on the discussion by talking specifically about the approach Core ContributorsCore ContributorsCore contributors are those who have worked on a release of WordPress, by creating the functions or finding and patching bugs. These contributions are done through Trac.
https://core.trac.wordpress.org take to managing the performance of the CoreCoreCore is the set of software required to run WordPress. The Core Development Team builds WordPress. Editor itself!
Think of Core Editor Performance as impacting the user experience when creating content. It’s the difference between a jarring experience, with the editor barely keeping up as you type, and a creative one — where adding dynamic content is a breeze with performance hardly being noticeable.
With each release of GutenbergGutenbergThe Gutenberg project is the new Editor Interface for WordPress. The editor improves the process and experience of creating new content, making writing rich content much simpler. It uses ‘blocks’ to add richness rather than shortcodes, custom HTML etc.
https://wordpress.org/gutenberg/, a performance benchmark is run against the last few releases that compares different response times for a large post (~36,000 words, ~1,000 blocks). You can find this benchmark at the bottom of each “What’s New in Gutenberg” post. While this approach doesn’t cover every scenario, and absolute numbers are not intrinsically meaningful, it has helped identify variations in performance for different releases. Generally speaking, while the loading time of the editor is important, pay special attention to typing speed (also known as KeyPress Event speed). This is a far more important measure when it comes to user experience as this is what allows for the smooth experience when working in the editor.
Beyond an overview of neat numbers, what does focusing on Core Editor Performance entail? Pulling from the documentation, the following overall metrics are tracked:
Loading Time: The time it takes to load an editor page.
Typing Time: The time it takes for the browser to respond while typing on the editor.
BlockBlockBlock is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. Selection Time: The time it takes for the browser to respond after a user selects a block. (Inserting a block is also equivalent to selecting a block. Monitoring the selection is sufficient to cover both metrics).
Do you have something to propose for the agenda, or a specific item relevant to our standard list above?
Please leave a comment, and say whether or not you’ll be in the chat, so the group can either give you the floor or bring up your topic for you, accordingly.
This meeting happens in the #core channel. To join the meeting, you’ll need an account on the Making WordPress Slack.
A refactor of the core Gallery Block has been worked on over the last couple of months which will move it from a list of image tags within the blockBlockBlock is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. content to nested Image blocks using InnerBlocks. The hope is this change will make things easier for both users and developers.
Why the change?
The fundamental reason for this change is to make images behave the same in the editor whether they are used as single blocks or as part of a gallery. For example, for users, this update means that Gallery images would automatically have the ability to add custom links for each image! It’s also easy now to replace a single image directly. Other benefits include being able to use the standard move, drag and drop, copy, duplicate, and remove block functionalities. Keyboard navigation also benefits from the standard block model.
There have been open issues related to this inconsistency for some time:
To get around this inconsistency, pluginPluginA plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party. developers often have to duplicate all of the Image block functionality in custom Gallery block plugins. Tied to this, plugins that extend the image block haven’t been able to benefit galleries directly. With this change making image behaviour more consistent between stand-alone images and those within the gallery, more custom gallery functionality can be implemented as Block Styles or Block Variations of the coreCoreCore is the set of software required to run WordPress. The Core Development Team builds WordPress. Gallery block instead of creating a completely new gallery block.
With each image being a block, server operations are also much more straightforward since you can get the image IDs directly.
In depth testing needed
While the expectation is nothing changes in terms of output for the end-user, this is a pretty major change on a technical level for a very popular block, including a change in the underlying markup to align it with the W3C WAI guidelines on the grouping of images, so it’d be a huge help to gather as much testing feedback as possible.
Accessing the new Gallery Block
To test the new Gallery block, you can either checkout the Gallery refactor PR branch and test in a local dev environment, or you can download the Gallery refactor plugin build and install it on any WordPress test site. Once installed you need to enable the experimental setting ‘Enable the refactored gallery block’:
Only new gallery blocks added after the experimental flag is turned on will be in the new format, all existing galleries will be editable and viewable in the current format. You can manually transform an old format gallery to the new format using the block transform menu and choose the ‘Gallery’ option.
Important note — only run the Gallery refactor experimental feature on test data
Although any existing gallery saved content should be unaffected, if you transform these to the new format, or add new gallery blocks in the new format, these blocks will be broken if the experimental feature is removed …. so don’t run the gallery refactor build against any critical data that you don’t have a backup of.
How can I be sure I am seeing the new gallery block?
When adding a Gallery block with the refactored gallery, selecting an individual image in a gallery should show you the same options as for an individual Image block. Currently, the only settings that will be missing are align and resize as these options break the gallery column layout.
Please note that this experimental feature will not currently work in FSE templates. To see the new gallery block you will need to add the block to a standard post or page. This change is also not ported to native mobile builds yet.
If you are the author of a plugin or theme that extends or restyles either the Image block or the existing Gallery block you should:
Test how running the new Gallery block format affects the display of existing content in the editor or front end.
Test your plugin or theme against an existing gallery that has been migrated to the new format.
Test with new galleries added with the refactored block.
Test how an Image block extensions affect layout, etc. if the Image block is nested within one of the new Gallery blocks.
Where to report issues
Please leave feedback in the comments of this post. If you’d prefer, you’re always welcome to create issues in this GitHub repo directly for GutenbergGutenbergThe Gutenberg project is the new Editor Interface for WordPress. The editor improves the process and experience of creating new content, making writing rich content much simpler. It uses ‘blocks’ to add richness rather than shortcodes, custom HTML etc.
https://wordpress.org/gutenberg/. If you leave feedback in GitHubGitHubGitHub is a website that offers online implementation of git repositories that can easily be shared, copied and modified by other developers. Public repositories are free to host, private repositories require a paid subscription. GitHub introduced the concept of the ‘pull request’ where code changes done in branches by contributors can be reviewed and discussed before being merged by the repository owner. https://github.com/, please do still comment below with the link. Please check against the known issues list before reporting.
Welcome back to a new issue of Week in CoreCoreCore is the set of software required to run WordPress. The Core Development Team builds WordPress.. Let’s take a look at what changed on TracTracAn open source project by Edgewall Software that serves as a bug tracker and project management tool for WordPress. between March 15 and March 22, 2021.
24 commits
21 contributors
92 tickets created
7 tickets reopened
85 tickets closed
Reminder: WordPress 5.7.1 is planned for April 14, 2021, so we are currently in the development cycle of the next point releaseMinor ReleaseA set of releases or versions having the same minor version number may be collectively referred to as .x , for example version 5.2.x to refer to versions 5.2, 5.2.1, 5.2.3, and all other versions in the 5.2 (five dot two) branch of that software. Minor Releases often make improvements to existing features and functionality..
TicketticketCreated for both bug reports and feature development on the bug tracker. numbers are based on the Trac timeline for the period above. The following is a summary of commits, organized by component.
Code changes
Administration
Make focus states consistent in adminadmin(and super admin) menu when collapsed – #32579
Move the get_current_commenter() method next to the test it’s used in – #52625
Correct some newly introduced @covers tags – #39265
Coding Standards
Move some translator comments to the correct place – #52627
Add missing semicolon to some endif keywords – #52627
Use strict comparison for return type checks in a few functions – #52627
Use strict comparison in wp-admin/includes/class-wp-upgrader.php – #52627
Add a space before / character in some self-closing HTMLHTMLHyperText Markup Language. The semantic scripting language primarily used for outputting content in web browsers. tags – #52870
Use strict comparison for JSJSJavaScript, a web scripting language typically executed in the browser. Often used for advanced user interfaces and behaviors. fragment in some admin files – #52845, #41988
Documentation
Fix typo in pre_term_linkfilterFilterFilters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. description – #52628
Correct formatting for the description of some register_post_type() parameters – #52836
Emoji
Update the Twemoji library to version 13.0.2 – #52852
External libraries
Update generated script loader version hashes – #52850
Further fix jQuery deprecations in WordPress core – #51812
Please join me to welcome our 2 new Core contributorsCore ContributorsCore contributors are those who have worked on a release of WordPress, by creating the functions or finding and patching bugs. These contributions are done through Trac.
https://core.trac.wordpress.org of the week ♥️ @nayanchamp7 and @wangql
GutenbergGutenbergThe Gutenberg project is the new Editor Interface for WordPress. The editor improves the process and experience of creating new content, making writing rich content much simpler. It uses ‘blocks’ to add richness rather than shortcodes, custom HTML etc.
https://wordpress.org/gutenberg/ 10.3 release.
BlockBlockBlock is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. based WidgetWidgetA WordPress Widget is a small block that performs a specific function. You can add these widgets in sidebars also known as widget-ready areas on your web page. WordPress widgets were originally created to provide a simple and easy-to-use way of giving design and structure control of the WordPress theme to the user. Editor.
Navigation Block.
Full Site Editing.
Task Coordination.
Open Floor.
If you can’t attend the meeting, you’re encouraged to share anything relevant for the discussion:
If you have anything to share for the Task Coordination section, please leave it as a comment on this post.
If you have anything to propose for the agenda or other specific items related to those listed above, please leave a comment below.
GutenbergGutenbergThe Gutenberg project is the new Editor Interface for WordPress. The editor improves the process and experience of creating new content, making writing rich content much simpler. It uses ‘blocks’ to add richness rather than shortcodes, custom HTML etc.
https://wordpress.org/gutenberg/ Version 10.2
The last round of mockups for the global styles sidebar are live. It has provided a good ground to re-evaluate the theme.jsonJSONJSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. format and there’s going to be some formalization of the concept of “elements”, see #29891 for details.
There’s ongoing work for translations #29828 and iterate to offer higher-level APIs in the server #29667#29905
We landed some fixes for sub-properties (padding) as well #29712
This issue description has been updated to focus on the infrastructure parts of global styles, that we aim to ship in 5.8. The UIUIUser interface tasks have been moved to the backlog for clarity but will be re-evaluated at a later point.
Continued landing improvements for recently merged Persistent List View. The last one added some nice styles for select and hover states (#29636)
We experimented with adding contextual blockBlockBlock is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. pattern inserter for semantic template parts (#29595) and gave up on that approach for now. That will probably be handled by contextual pattern transformations instead (#29890)
Weird template saving issue after switching FSE themes was reported in #28951, and we are looking into fixing it in #29842.
Continuing to test FSE every day and filing issues as I come across them.
Chatted with Taylor Ardnt about a11yAccessibilityAccessibility (commonly shortened to a11y) refers to the design of products, devices, services, or environments for people with disabilities. The concept of accessible design ensures both “direct access” (i.e. unassisted) and “indirect access” meaning compatibility with a person’s assistive technology (for example, computer screen readers). (https://en.wikipedia.org/wiki/Accessibility) in FSE and filed various issues.
Suggest Block patterns in block placeholder states is awaiting some updates in block patterns PR 29602
Both try to validate the experimental `scope` in Patterns APIAPIAn API or Application Programming Interface is a software intermediary that allows programs to interact with each other and share data in limited, clearly defined ways. introduced here PR 28891 and more explorations around all these and Template Parts are needed.
This week I focused on tasks needed for the FSE MVPMinimum Viable Product"A minimum viable product (MVP) is a product with just enough features to satisfy early customers, and to provide feedback for future product development." - WikiPedia. That means primarily working on items outlined in Issues 22724
Other than that lots of PR reviews to keep the cogs moving
Created PR 29919 to fix the issue with the Image Block resizable box
Created PR 29825 add a filterFilterFilters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. for “Preferences” modal sections. Would like feedback and eyes here. @youknowriad provided feedback on the extensibility of JSJSJavaScript, a web scripting language typically executed in the browser. Often used for advanced user interfaces and behaviors. in Gutenberg which needs an architecture document
Currently working on PR to use image_default_size option in Image Block, instead of hardcoded default.
Open Floor
A new GithubGitHubGitHub is a website that offers online implementation of git repositories that can easily be shared, copied and modified by other developers. Public repositories are free to host, private repositories require a paid subscription. GitHub introduced the concept of the ‘pull request’ where code changes done in branches by contributors can be reviewed and discussed before being merged by the repository owner. https://github.com/ Project Board was created for the Full Site Editing MVP due in April. Shoutout to @paaljoachim for championing the effort and to @priethor for assisting. Feedback on the next round of FSE testing Create a 404 Page is due Wednesday.
As noted by @matias during the meeting, more feedback is needed from theme creators and testers taking part in the FSE Outreach Experiment on the theme.json proposal.
Since the release of WordPress 5.7 a small number of bugs have been identified will benefit from a maintenance release.
Now, it’s time to merge these changes into a new WordPress minor releaseMinor ReleaseA set of releases or versions having the same minor version number may be collectively referred to as .x , for example version 5.2.x to refer to versions 5.2, 5.2.1, 5.2.3, and all other versions in the 5.2 (five dot two) branch of that software. Minor Releases often make improvements to existing features and functionality. and to address the other tickets that have appeared in the meantime.
The following release schedule is being proposed:
Release Candidaterelease candidateOne of the final stages in the version release cycle, this version signals the potential to be a final release to the public. Also see alpha (beta).: Wednesday 7 April, 2021 around 23:00 UTC
Final release: Wednesday 14 April, 2021 around 23:00 UTC
In line with the trial for consistent minor release leads for each major branchbranchA directory in Subversion. WordPress uses branches to store the latest development code for each major release (3.9, 4.0, etc.). Branches are then updated with code for any minor releases of that branch. Sometimes, a major version of WordPress and its minor versions are collectively referred to as a "branch", such as "the 4.0 branch"., the release leaders for the 5.7.x releases will be:
Release leadRelease LeadThe community member ultimately responsible for the Release.: @peterwilsoncc
@francina then turned to posts that need feedback. This Proposal: A WordPress Project Contributor Handbook drew spirited emoji support from the group. Francesca also reminded the group to sign up for the Updates blog to keep up with a variety of team updates, as well as posts from @chanthaboune about cross-team efforts and the latest news from leadership.
Components check-in and status updates
@sergeybiryukov started with jQuery news: the version in trunktrunkA directory in Subversion containing the latest development code in preparation for the next major release cycle. If you are running "trunk", then you are on the latest revision. has updated to 3.6.0, which is mostly bugbugA bug is an error or unexpected result. Performance improvements, code optimization, and are considered enhancements, not defects. After feature freeze, only bugs are dealt with, with regressions (adverse changes from the previous version) being the highest priority. fixes and improvements. Two callouts:
Aside from the change to no longer ensure XHTML-compliant tags for you, we do not expect other compatibility issues when upgrading from a jQuery 3.0+ version.
See ticketticketCreated for both bug reports and feature development on the bug tracker.#52707 for more details.
jQuery hoverIntent library has updated from version 1.8.3 to 1.10.1. The changes all appear to be minor.
@adamsilverstein checked in with Media news: he’s working on landing support for WebP images in 5.8 and would like testing and feedback on ticket #35725.
Up next, @audrasjb said he has nothing new for Menus and WidgetWidgetA WordPress Widget is a small block that performs a specific function. You can add these widgets in sidebars also known as widget-ready areas on your web page. WordPress widgets were originally created to provide a simple and easy-to-use way of giving design and structure control of the WordPress theme to the user., but he’s quietly scrubbing bugs and watching tickets. On Upgrade/Install, he highlighted this feature plugin proposal post.
@sabernhardt wrapped up the Component updates with his announcement of a Toolbar triagetriageThe act of evaluating and sorting bug reports, in order to decide priority, severity, and other factors./bug scrub for the following day, March 18, at 16:00 UTC.
The discussion that followed outlined a general process—notify, then act—but pointed out the group still needs to make a specific plan for IE11. Adam noted that IE11 is the only major browser that doesn’t support WebP images.
@desrosj said there might already be a notification in place. @adamsilverstein found a ticket, #48743, to that effect. Further discussion also made it clear that the team needs to do more to announce the change, including stronger language in relevant tickets (@desrosj and @audrasjb), a News blogblog(versus network, site) post (h/t: @jorbin) and relevant Handbook updates (h/t @jeffpaul)
It seems that most of WP users (outside of the contributing teams) are still largely unaware that full-site editing is coming later this year.
Perhaps that’s intentional, but once we have something stable to test, have we considered adding a dashboard widget to one of the upcoming minor releases, to invite more users to test FSE before final release, like we did with GutenbergGutenbergThe Gutenberg project is the new Editor Interface for WordPress. The editor improves the process and experience of creating new content, making writing rich content much simpler. It uses ‘blocks’ to add richness rather than shortcodes, custom HTML etc.
https://wordpress.org/gutenberg/ in #41316 for WP 4.9.8?
Reminder: A next week’s meeting on March 25 we will share mock-ups with color custom property naming for another UIUIUser interface component besides the button.
Simply put, and taken from the TypeScript website:
TypeScript extends JavaScriptJavaScriptJavaScript or JS is an object-oriented computer programming language commonly used to create interactive effects within web browsers. WordPress makes extensive use of JS for a better user experience. While PHP is executed on the server, JS executes within a user’s browser.
https://www.javascript.com by adding types.
You are able to add types by using the TypeScript language itself, which is a superset of JavaScript. It resembles JavaScript in every way except for the addition of types. Alternatively, you can add types through JSDoc annotations. GutenbergGutenbergThe Gutenberg project is the new Editor Interface for WordPress. The editor improves the process and experience of creating new content, making writing rich content much simpler. It uses ‘blocks’ to add richness rather than shortcodes, custom HTML etc.
https://wordpress.org/gutenberg/ so far has opted for the latter.
Type checking is also coming to PHP and many other dynamic languages, so increasingly type checking is becoming less of a foreign concept for fans of dynamic languages.
What is being proposed?
This post proposes that we transition away from JSDoc annotations and towards the TypeScript language itself. This is proposed because it unlocks powerful features of TypeScript that are unavailable through JSDoc annotations and will encourage new contributions by community members in this space by lowering the learning curve and leveraging existing knowledge of statically typed languages.
Essentially this means beginning to use .ts(x) files in addition to existing .js files. I emphasize “in addition to” because I want to stress that I am not suggesting that we eliminate traditional JavaScript from Gutenberg, nor is the proposal to fully re-write Gutenberg in TypeScript. The fact is that the majority of Gutenberg will probably forever remain as plain old JavaScript. However, I think in our coreCoreCore is the set of software required to run WordPress. The Core Development Team builds WordPress. libraries (data, compose, components, dom, etc) we should transition to a heavier use of type-checking and the TypeScript language itself to ease that transition.
While Gutenberg packages are not authored in TypeScript, we can still benefit from its JavaScript type checking using the JSDoc we already write. This will bring us some benefit of type safety, even as we continue to write modules with JavaScript, not TypeScript.
We use TypeScript to generate .d.ts files for certain packages in Gutenberg based on JSDoc type annotations. This allows us to “sprinkle” TypeScript support throughout our normal JavaScript codebase without having to do re-writes of existing modules in TypeScript. In addition to generation the TypeScript compiler also checks our code for type safety. For example, you type the a function like this:
/**
* @param {number} x
* @param {number} y
* @return {number}
**/
function add( x, y ) {
return x + y;
}
And try to pass in a string to this function, you’ll get a compiler error. This is enforced through a pre-commit hook as well as the static-analysis GitHubGitHubGitHub is a website that offers online implementation of git repositories that can easily be shared, copied and modified by other developers. Public repositories are free to host, private repositories require a paid subscription. GitHub introduced the concept of the ‘pull request’ where code changes done in branches by contributors can be reviewed and discussed before being merged by the repository owner. https://github.com/ action that is run on all PRs.
Problems with the JSDoc approach
When we adopted JSDoc annotations as our approach to adding types in Gutenberg, we hoped we could improve the experience for new contributors by providing great auto-complete and quality assurance help in editors like VS Code while not requiring them to actually learn TypeScript. However, adopting the JSDoc syntax actually has significant downsides. First, few TypeScript examples use JSDoc. When a new contributor wants to express a moderately complex type, they find themselves translating between TypeScript example they find online and the less common, JSDoc version. Second, there are some features of TypeScript that are completely unavailable in the JSDoc variant of the syntax. And those features, like template parameter defaults, can potentially provide a lot of help for developers trying to use Gutenberg’s components or the @wordpress/data package.
Surprise! We already use TypeScript (compiler)
By now you may have thought to yourself, “Wait, it sounds like we already use TypeScript?” The secret is that yes, we already use TypeScript in Gutenberg… just with the a poorly documented, less expressive syntax (JSDoc). For packages that support it (those that already emit their own .d.ts files) the TypeScript compiler is already being used for type checking, as stated above with the addition example. Likewise, when reading JSDoc typed JavaScript code, one doesn’t need to just pay attention to the code they are immediately reading, but also displaced type definitions (the type definitions live separately from the code itself). This means that the effective difference between what exists today and what is being proposed in this post is a (massive) syntax improvement as well as the ability to unlock TypeScript’s full potential by being able to expressively type core libraries like compose and data.
While this is admittedly a new syntax and may seem scary, I would urge you to consider the difference between these two blocks of code:
This represents the majority of the changes that would occur if we adopted TypeScript in places where we currently use JSDoc.
I don’t want to discount the learning curve of a new language—TypeScript definitely has its own learning curve. However, I think that learning curve is worth the benefits elucidated in the following section. Likewise, regular JavaScript with JSDoc annotations will continue to be available as an option and for many use cases it will continue to be a good option (like adding types to existing code where the types themselves are straightforward).
For a while, this syntax improvement was not possible because we lacked tooling. For example, we didn’t have ESLint support and docgen was unable to process TypeScript files. Both of those problems have since been addressed in these PRs:
Now that these tooling issues are mostly behind us, I think we’re ready to move forward with native TypeScript in Gutenberg.
Benefits of native TypeScript
By allowing native TypeScript support in the Gutenberg repository, we continue to leverage the existing benefits we’ve already bought into by using the TypeScript compiler to generate .d.ts files (remember that this does not merely extract the types from the JSDoc comments but also checks the soundness of the code itself) with the vastly improved syntax of native TypeScript. It’ll also allow us to leverage the existing expertise of members of our community who are familiar with TypeScript (and other typed languages) rather than having to re-learn how to write types using the far-less than ideal JSDoc support.
Native TypeScript will also unlock the full power of the TypeScript type system. Currently there are a few edge cases that are explicitly not supported by the JSDoc annotations. For example, it’s not possible to create optional type parameters. The following is impossible to express in JSDoc:
type GenericType<T = any> = { foo: T };
Furthermore, native TypeScript will allow us to type complex core systems (like @wordpress/data and @wordpress/compose) without adding massive amounts of “noise” to each file in the form of complex, difficult to read, and even harder to maintain JSDoc type annotatons. For example, typing createHigherOrderComponent in native TypeScript is a breeze relative to the complex expressions you run into trying to type it using JSDoc annotations. Typing these core systems gives us both the guarantee of their soundness as we make improvements and grants community contributors using those libraries the same guarantee that they’re using the APIAPIAn API or Application Programming Interface is a software intermediary that allows programs to interact with each other and share data in limited, clearly defined ways. in a sound way.
Where should this change happen and who will it effect?
First, I want to emphasize that this changes basically nothing for custom blockBlockBlock is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. authors. While @wordpress/babel-preset-default includes TypeScript transpilation support, create-block has not been updated to support TypeScript. Likewise, the dependencies for block authors, like the @wordpress/block-editor package, do not have up-to-date type definitions (it has defintions on DefinitelyTyped but these have probably fallen out of sync with the code itself) or do not have type definitions at all (meaning the TypeScript compiler will complain about not being able to understand your dependencies). TypeScript for block authors will likely take some significant community support to enable type generation, whether through native TypeScript or JSDoc type annotations, in higher-level packages.
That being said, let’s take a look at who is already affected by TypeScript in the Gutenberg code base. One third of Gutenberg packages are currently type checked (meaning they have a tsconfig.json), either fully or partially and the pre-commit hook won’t let you commit and JSJSJavaScript, a web scripting language typically executed in the browser. Often used for advanced user interfaces and behaviors. code there that wouldn’t be approved by the TypeScript compiler. To make any contribution to this growing list of packages, you must already know the TypeScript type system in order to understand type checking errors as well as to understand how to type any new code that you add. This has been the status quo for many months now (see the history section above).
Taking a closer look at the packages that currently garner the most contributions per year, here are the packages that have attracted more than 100 commits in the last year:
package
commits
tsconfig
@types
block-library
1093
x
block-editor
950
x (partial)
x
components
626
x (partial)
x
e2e-tests
454
edit-site
292
editor
257
x
edit-post
246
x
edit-widgets
163
reactReactReact is a JavaScript library that makes it easy to reason about, construct, and maintain stateless and stateful user interfaces.
https://reactjs.org-native-editor
152
edit-navigation
135
scripts
116
blocks
114
block-directory
107
interface
102
The tsconfig and @types columns denote whether the package is type checked or has DefinitelyTyped type defintions respectively. At the moment, none of these 14 packages publish type definitions natively and community contributors who use TypeScript for their projects must rely on DefinitelyTyped when it is available.
The block-library package type checks 2 specific files and ignores the rest (for now, hopefully this will be expanded in the future).
This shows that for the vast majority of contributions, TypeScript support is irrelevant. Now, that doesn’t meant that TypeScript support isn’t coming to those packages. The main roadblock to it, however, are lower level packages that are currently untyped like compose and data.
components is a bit of an outlier in that it is a widely contributed-to package that has a lot of it typed. Indeed there is an ongoing effort to type as much of components as possible, due to its wide-spread nature. It is believed that the best way to show TypeScript’s power is to have a widely used library like components typed. However, it is roadblocked by compose and other core libraries not being fully typed.
Those low level packages garner far fewer contributions by a much smaller group of people than the 14 packages listed in the table above. compose, for example, received under 60 significant (non publish, non dependency update, and non documentation update) commits over the last year from a group of less than 10 people. By progressively and carefully re-writing parts of compose in native TypeScript, we can have a ripple effect where the benefits of TypeScript will by felt throughout the Gutenberg codebase without actually affecting how most contributors write their code. Most contributors consume compose in their own code but do not contribute directly to it.
In summary, there are a few packages like compose, element, i18n, and data that share the following traits:
they are foundational infrastructure packages relied on by everything else
they don’t attract mainstream contributor interest. They are worked on mainly by “experts”
they are more likely to use complicated types with generics and other tricks. Functions from compose are a crystal clear example of that
Switching these to native TypeScript would have a big impact: solid type-safe foundational libraries. And the downside is limited: most contributors don’t come into much contact with these.
The path forward
In packages that support JSDoc type annotations, you can already swap out JavaScript for TypeScript without any concern as Babel is already ready to consume TypeScript (it simply strips the type annotations from the files). For example, if you wanted to re-write and any file that is already JSDoc annotated in TypeScript, you could do that today without any problems (really, if you don’t believe me try it!). There may be some caveats like needing to explicitly annotate return types of functions so that docgen can consume them, but these are easy to enforce, beneficial to the health of the code in general, and also not different than the limitations that currently exist with JSDoc—docgen will give you a helpful error if it cannot find the return type of a function you’ve asked it to document and explicit annotation of inputs and outputs is a good thing and we already do it through the @returntagtagA directory in Subversion. WordPress uses tags to store a single snapshot of a version (3.6, 3.6.1, etc.), the common convention of tags in version control systems. (Not to be confused with post tags.).
For packages that are currently not type fully annotated (like compose, dom, and data) we can begin to progressively re-write the more complex, core parts of it in TypeScript. We don’t have to re-write everything, nor should we spend our valuable time merely re-writing files that don’t need it. However, in the cases where native TypeScript allows us to more fluidly, confidently, simply, and beautifully express the types of a module, we should do so (compose and data are tremendous examples of this).
We’ve already seen some of the benefits of using TypeScript JSDoc syntax in Gutenberg. Our documentation has improved, and everyone from Gutenberg contributors to block developers to site builders enjoys better auto-complete and error handling in their editors. When we use the better supported, more expressive standard TypeScript syntax, we’ll only improve that experience for everyone involved. If you want to contribute to Gutenberg, don’t be intimidated by the new syntax! TypeScript, much like WordPress, enjoys a rich, supportive community with many quality examples and tutorials.