Needs work
Project:
Drupal core
Version:
main
Component:
theme system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
2 Sep 2011 at 20:29 UTC
Updated:
17 Dec 2025 at 08:20 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
draenen commentedPatch removes newlines.
Comment #2
draenen commentedComment #3
tr commentedThis needs to go into D8 first.
Comment #4
c960657 commentedPatch no longer applies to D7 – requires a reroll.
Also, please provide a patch for D8 also.
Comment #5
draenen commentedComment #7
tr commentedYou have to change the test too, because the test is expecting the theme function to output the "\n".
Comment #8
draenen commentedTrying again. The newline character is acceptable (even preferred) in most cases, so we'll just add a #newline option that can be set to false.
Comment #9
tr commented8: newline-causes-unwanted-whitespace-1268180-6.patch queued for re-testing.
Comment #11
star-szrProbably the most relevant issue to look at is #1825090: Remove theme_html_tag() from the theme system, not sure if this is still relevant for 8.x or not.
Comment #14
andypostComment #15
andypostComment #16
lokapujyaComment #17
andypost#8 makes BC
why this was removed in reroll?
Comment #19
lokapujyaStep by Step. The theme function was converted to a render array so the code is very different. It's not a typical reroll, but a start from scratch. So, now #16 shows which tests break without making the newline optional.
*If someone wants to add that parameter in, I probably won't have any time to work on it for a few days.
Comment #21
joelpittetDo we really need this to be BC? I'd suggest we don't add the BC layer for this and just fix it. Whitespace around block elements shouldn't be expected, IMO. It breaks more things than it solves.
Comment #23
andypostfix remaining tests
Comment #25
andypostfix leftovers
Comment #26
joelpittetThank you for fixing the remaining tests @andypost
Comment #27
xjmThemey things.
Comment #28
alexpottLet's change these to single quotes. Considering we've changed this elsewhere.
Comment #29
andypostFixed #29 + trailing comma
Comment #30
star-szrLooks like this needs a reroll after #2687897: Convert system module's kernel tests to NG otherwise looking good I'd say. I do wonder if we should consider adding a change record here because contrib may be relying on the whitespace in automated tests as well. I'd also like to bump this to 8.2.x for that reason and I agree no BC layer is needed.
Comment #31
dimaro commentedRerolled #29.
Patch against 8.2.x
Comment #32
andypostCR filed https://www.drupal.org/node/2742955 needs review
Comment #33
andypostI think that ready, CR review could be done later
Comment #34
alexpottThis is where a visual regression test would be super useful.
Comment #35
xjmDiscussed #34 with @alexpott; this is more a proposal for followup work. For this issue, thorough manual testing and the CR are sufficient. We are also making the change in 8.2.x only per @Cottser's feedback in #30, because of the risk of disruption.
Assigning to @Cottser for review. Thanks everyone!
Comment #36
star-szrAfter poking around with this one I think we need to consider this further. This makes the page source rather hard to read in spots. Maybe everyone uses a web inspector but I'm not sure about this for DX/TX and so on. One potential idea would be to always include the whitespace for elements that we know are non-rendering like meta, link, script, etc. but not sure how viable that is.
View source before the patch:
After:
<meta charset="utf-8" /><meta name="Generator" content="Drupal 8 (https://www.drupal.org)" /><meta name="MobileOptimized" content="width" /><meta name="HandheldFriendly" content="true" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><link rel="shortcut icon" href="/core/misc/favicon.ico" type="image/vnd.microsoft.icon" /><link rel="alternate" type="application/rss+xml" title="" href="http://d8.dev/en/rss.xml" />If you look at the scripts at the bottom of the page it's an even bigger pile of messiness.
Comment #37
joelpittetThat is a good point @Cottser. Let's add the \n character back to the elements that go into the head. There are only a few places that would be needed.
See attached patch and interdiff
Comment #39
joelpittetMay still have a fail in there, but this is the tweak because one of the test is rendering them through the asset collection renderers so it has the \n
Comment #40
andypost#36 is really debatable, 99% of time better to have page size smaller but for me having new line for header is fine
Comment #42
joelpittetThis is going to fail too on bigpipe. There is an extra line in the output. Fixes the other test, the order of the keys was the fail there.
Comment #44
andypost@Joel I can't find why https://www.evernote.com/shard/s710/sh/fc945925-4056-4035-846f-8ca414577... that happens, I will try to find time this WE
Comment #45
joelpittetNo worries, I think I found it. Went a bit far on removing the \n from a test case for a
<linkthat wasn't being built by the other stuff.Comment #46
andypostYay, thanx a lot!!! Let's get this finally in
Comment #47
joelpittetBack to @Cottser for the word
Comment #48
star-szrHmm I was thinking the change would be in the HtmlTag element, not a bunch of places where we use that element. This method seems like it'll be inconsistent if anyone outside of core uses
'#type' => 'html_tag'with link, meta, etc.Comment #49
joelpittet@Cottser, I'd rather not muddy the tag with exceptions/conditional code. IMO it shouldn't be expected that we are putting whitespace on tags or specific tags, and if someone wants to that they can do as I did in the patch with
'#suffix' => "\n"The exceptions are explicit to the parts of the code where they are 'needed'. They are only really useful in dev, in production I'd even remove those '\n', but don't want to scope creep this.
Comment #50
andypost@Cottser there's 2 separate tasks discussed:
1) *bug* the issue - unwanted whitespace
2) dev time setting to have
head"fine-printed - looks like follow-upSuppose better commit #31 and discover "developer setting" in follow-up issue
Comment #51
andypostSuppose page size optimization is small but it is
Comment #52
star-szrAssigning to @alexpott for a second opinion since he reviewed this as well.
Comment #53
alexpottI think we should get this into 8.3.x early so we have a chance to catch any regressions this might cause during the cycle. The issue makes sense and seems a good idea.
Comment #54
joelpittetLet's get this in early then. @Cottser, does the rational hold water or need more discussion?
Comment #55
alexpottThe potential effects of this behaviour change concern me. I agree with the change but I don't think we should be making it Drupal 8. The potential to break contrib and real sites in unexpected and untested ways is high. I think we need to add a #nonewline option HtmlTag's properties and use it where appropriate. And then if anyone wants to suppress it they can. And we can change the behaviour in Drupal 9.
I'm not sure this issue should have the performance tags.
Comment #56
andypost@Alexpott this about of extra browser timing - lots of useless text elements created and bit more bytes transfered, also this very related to #736066: ajax.js insert command sometimes wraps content in a div, potentially producing invalid HTML and other bugs
#nonewlinemakes sense but default better to set to optimizedI think 6 month adoption cycle should be enough to revert in case of problems
Comment #57
alexpott@andypost I understand this might cause bugs but so might changing the default behaviour. Wrt to frontend performance - I like to see evidence of how impactful this is going to be.
Comment #59
joelpittetReroll
Comment #60
andypostreroll, removed unneeded changes in
core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php+ added fixes for
core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.phpafter #2694535: Support rect property and nested render arrays in html_tag for dynamic SVGsComment #62
andypostAnother reroll
Comment #64
andypostNew test from #2660124: Dynamically build layout icons based on well formed config needs fixes
Comment #67
andypostRe-roll & fix broken tests
Comment #69
andersen_ti commentedRe-rolled.
Was conflict in CssCollectionRenderer.php and CssCollectionRendererUnitTest.php cos IE 9 support removed from core and render function was cahnged.
Comment #71
andypostSo instead of suffix it could be option of element, so contrib/custom can override default
Patch adds this option with test & reverts mostly all changes
Comment #73
andypostbot flux
Comment #74
lokapujyaSo the new solution is not to remove the space, but to allow a way to remove it? Is anyone really going to use this feature and even know that it exists? Probably, they may just fix it with CSS.
Comment #75
lokapujyaAs we can see, fixing the default behaviour breaks some tests (which cause us to have to fix those tests). We now were able to remove the changes to those tests because we aren't changing the default behavior. That will get revisited when the TODO is looked at for D9.
Comment #76
andypostThat's main problem to move this forward - how to allow change for D9
Probably this todo should be removed...
Comment #77
andypostComment #81
daniel kulbeDoes not apply against 8.9.x anymore. Here's a re-roll.
Comment #83
nikitagupta commentedfixed the test cases.
Comment #85
daniel kulbeComment #86
daniel kulbeFor
"drupal/core": "~9.2.5"Comment #87
daniel kulbebroken patch ... sorry for the noise
Comment #88
daniel kulbeComment #89
ckidowComment #90
longwaveThe test changes in #83 onwards are all wrong, void elements should not have a closing tag.
I am not sure if we need to introduce a new property, can we go back to using
#suffixand warn users with something like this?Then we can explicit set
'#suffix' => ''where we want to strip the newline already.Comment #95
andypostComment #96
andypostAddressed #90
- reverted changes to #81 (interdiff against it)
- added deprecation (needs to update CR)
After full test suite gonna add test for deprecation (looking for better wording)
Comment #97
andypostbit more clean-up
Comment #98
andypostAdded test and fixed existing to prevent throwing deprecation
Comment #100
heddnThe test failures show it. How do we trigger warnings without causing a lot of noise for tests?
Comment #101
andypostThis condition needs improvement at least a global kill-switch in settings.php to enable BC mode
Comment #102
longwaveWonder if we just make this change in a minor, and a change record/release note is enough. Deprecating on unset #suffix is very noisy and I think 99% of users won't care that we make this change.
Comment #103
wim leers#102++
Comment #104
andypost...in a light of https://wiki.php.net/rfc/opt_in_dom_spec_compliance
probably better to split out deprecation of
#suffixinto separate issue at least to unlock itComment #105
andypost