Opened 2 months ago
Closed 40 hours ago
#64442 closed enhancement (fixed)
Deprecate and remove HTML5 script theme support
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Script Loader | Keywords: | has-unit-tests needs-dev-note has-patch |
| Focuses: | javascript | Cc: |
Description (last modified by )
HTML5 script theme support is not worth considering today, themes do not control and are not concerned with HTML5 script rendering. Data suggests that the overwhelming majority of page views are HTML5, not XHTML (props @westonruter) and theme scripts are not broken regardless of their declared support.
This declared support has two impacts, it will add a type attribute to script tags and it will add CDATA wrappers.
This is an inline script without declared HTML5 script support:
<script type="text/javascript" async="async"> /* <![CDATA[ */ "script contents"; /* ]]> */ </script>
And the same script with support:
<script async> "script contents"; </script>
#64428 proposes removal of the type attribute on scripts and styles. This ticket focuses on all aspects of theme support for HTML5 scripts. Declaring HTML5 script support can be deprecated, and the CDATA and type attribute removed.
The CDATA wrappers are redundant for JavaScript in HTML5 and are harmful where script tags do not contain JavaScript (#60320). The HTML5 checks add needless complication to code.
The redundant attribute and CDATA wrappers are only relevant for XHTML. This requires the appropriate Content-Type: application/xhtml+xml HTTP header to be sent, something that themes do not appear to do. The HTTP content type header is more closely tied to server configuration (PHP defaults to text/html) than theme support. Themes do not really know whether a page will be served and interpreted as XHTML.
Change History (34)
#3
@
2 months ago
+1 here too. If I remember right the reason this wasn't fixed years ago was to support xml compatible output. Not sure if that's needed any more. If yes, there seem to be filters that can be used to add the type and CDATA comments back.
#4
@
2 months ago
Agree with the direction here. The XML/XHTML compatibility reasoning make sense historically, and it is good that filters still allows restoring type/CDATA if needed.
This ticket was mentioned in PR #10660 on WordPress/wordpress-develop by @jonsurrell.
2 months ago
#5
- Keywords has-patch has-unit-tests added
- Remove CDATA wrappers from script-loader
- Remove CDATA wrappers from script tests
Trac ticket:
#6
@
2 months ago
Should this ticket involve any changes to things like current_theme_supports() to indicate that HTML5 scripts are effectively always supported? For example, current_theme_supports( 'html5', 'script' ) would always return true.
#7
@
2 months ago
to support xml compatible output
The XML/XHTML compatibility reasoning make sense historically
I think the idea made sense historically more than the practice. we have the ability to convert HTML into XML now, which today is definitely the preferred mechanism, and would have been had the tool been available in the past.
and this is because there is so much more involved than adding self-closing flags and wrapping with CDATA sections.
I support this as well. Thanks @jonsurrell
#10
@
2 months ago
- Owner set to jonsurrell
- Resolution set to fixed
- Status changed from new to closed
In 61415:
#11
@
2 months ago
- Keywords needs-dev-note added; 2nd-opinion removed
This should have a mention in dev notes. It can be shared with #64428 (this comment).
#12
follow-up:
↓ 13
@
2 months ago
I’m not sure how to edit these, but we have a couple of dangling docs references that would be good to update.
add_theme_support()lists `script` in its example. This documentation page seems to mix the DocBlock content with “More Information” that comes from somewhere not in the source code. If that’s the case it makes me think about augmenting the HTML API docs, should we get the change to do so.- “Adding Theme Support” in the Codex lists `script` in its example.
Though I logged in to the Codex and the Edit link appeared, when I attempted to go ahead and make the change the page errored out with Exception encountered, of type "TypeError".
If none of us are sure how to update these pages we might want to ask in the #docs channel.
#13
in reply to:
↑ 12
@
2 months ago
Replying to dmsnell:
I’m not sure how to edit these, but we have a couple of dangling docs references that would be good to update.
Thank you, I've created this documentation issue to track the required changes.
#14
@
2 months ago
I do wonder what should be done when theme support is declared, checked, or removed for HTML5 script.
Should there be special handling like this?
add_theme_support( 'html5', array( 'script' ) )- ignored.remove_theme_support( 'html5', array( 'script' ) )- ignored.current_theme_supports( 'html5', 'script' )- alwaystrue.
#15
@
2 months ago
Should there be special handling like this?
This seems fitting, @jonsurrell, because many plugins appear to manually set the type attribute based on the current_theme_supports( 'html5', 'script' ) return value.
WP Directory uses of current_theme_supports() check for html5 and script.
#17
@
8 weeks ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening to consider how to handle current_theme_supports() and related functionality.
This ticket was mentioned in PR #10740 on WordPress/wordpress-develop by @jonsurrell.
7 weeks ago
#18
Support for non-HTML5 scripts has been removed in r61415.
This PR removes obsolete tests and mentions of non-HTML5 script behaviors.
Trac ticket: https://core.trac.wordpress.org/ticket/64442
#20
@
6 weeks ago
@jonsurrell I have added placeholders/scaffolds for this update in the HTML API Progress Report and the Updates to the HTML API in 7.0 posts.
I think that until the release we will probably need to keep adding stuff and then refining to make more cogent narratives and guides about the changes. For now, things probably look a bit chaotic and empty, but that’s the writing process.
#22
@
5 weeks ago
- Keywords needs-patch added; has-patch removed
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for some remaining work: https://core.trac.wordpress.org/ticket/64442#comment:14
This ticket was mentioned in PR #10919 on WordPress/wordpress-develop by @jonsurrell.
3 weeks ago
#23
- Keywords has-patch added; needs-patch removed
Since non-HTML5 script output was completely removed in r61415, all scripts are now output as HTML5. This change makes the theme support check reflect that reality by always returning true for script support, regardless of whether themes explicitly declare support.
The behavior of add_theme_support() and remove_theme_support() remains unchanged.
Only the check via current_theme_supports( 'html5', 'script' ) is affected.
Trac ticket: https://core.trac.wordpress.org/ticket/64442
## Use of AI Tools
@jonsurrell commented on PR #10919:
3 weeks ago
#24
This turns out to be messier than expected, largely because get_theme_support() and current_theme_supports() are both theme support lookup functions, but they both rely directly on the global $_wp_theme_features.
I think the cleanest way to implement this is to have current_theme_supports() rely on get_theme_support() and remove its use of the global. get_theme_support() can then be responsible for always declaring that 'html', 'script' support is enabled.
The alternative is to leave this as is (close this PR without landing). These checks are infrequent in plugins. `get_theme_support( 'html5' )` in particular is very minimal.
#25
@
3 weeks ago
Given how little html5 script support is apparently used outside of Core, I'm tempted to leave the behaviors of get_theme_support() and current_theme_supports() unchanged. I've described some of the difficulties I discovered on the linked PR.
This ticket can then close with some documentation that html5 script theme support is deprecated.
#26
follow-up:
↓ 27
@
2 weeks ago
Do I understand correctly that from 7.0, 'script' added like in the code example below will not do anything and the bundled themes should be updated to remove it?
And if they don't remove it now, nothing will break, it's just about tidying up.
add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script', 'navigation-widgets', ) );
#27
in reply to:
↑ 26
@
2 weeks ago
Do I understand correctly that from 7.0, 'script' added like in the code example below will not do anything and the bundled themes should be updated to remove it?
I would not remove 'script' from the array in themes that support WordPress versions prior to 7.0. Anyone who has a reason to update the theme but not core would suddenly have the type attribute and/or CDATA for scripts.
#29
@
13 days ago
- Milestone changed from 7.0 to 7.1
WP 7.0 pre-beta1 Triage:
Unfortunately this enhancement didn't make it before beta 1 code freeze. Thus, let's move it to milestone 7.1.
#30
@
9 days ago
- Milestone changed from 7.1 to 7.0
@audrasjb I'm switching this back to 7.0 milestone because the relevant behavioral changes have landed. The only remaining work I'm planning is to update some documentation, I believe that documentation changes can still be made. If that's inaccurate, please let me know.
This ticket was mentioned in PR #11061 on WordPress/wordpress-develop by @jonsurrell.
7 days ago
#31
HTML5 theme support script and style is no longer use by WordPress Core and does not convey relevant or accurate information.
Add a since annotation to indicate this.
@jonsurrell commented on PR #10919:
7 days ago
#32
Closing in favor of https://github.com/WordPress/wordpress-develop/pull/11061.
@jonsurrell commented on PR #11061:
7 days ago
#33
https://core.trac.wordpress.org/ticket/64442#comment:25:
Given how little html5 script support is apparently used outside of Core, I'm tempted to leave the behaviors of get_theme_support() and current_theme_supports() unchanged. I've described some of the difficulties I discovered on the linked PR.
This ticket can then close with some documentation that html5 script theme support is deprecated.
I'll mention some folks I've seen work with XHTML script tags in the past for their input: @swissspidy @dmsnell @westonruter @azaozz
This change seems like the next logical step after #42804 / [46164].