Page MenuHomePhabricator

Templates reusing a stylesheet triggers a warning, and the warning interfers with the adjacent sibling combinator
Closed, DeclinedPublic

Description

Reusing a template style in two or more templates that are stacked will trigger an additional link element after the first, something like

<div class="foo">…</div>
<link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r18514604">
<div class="foo">…</div>

The additional link element interferes with the adjacent sibling combinator, making it necessary to write really weird selectors.

The more proper solution would be to use the logging facility, or even the more obvious; to cache use of template styles and reuse previous instances as necessary.

Event Timeline

The link tags are for the benefit of applications that reuse snippets of page HTML (especially the mobileview API which can show individual page sections) or allow HTML editing (so the first stylesheet instance might be deleted) as these applications might need to restore some or all of the duplicate stylesheets.

Maybe we could use a HTML comment instead of a link tag but it would make handling it far more inconvenient.

This is simply weird… The adjacent sibling combinator is so common,… I would say it is perhaps the primary reason to use template styles and not the style attribute.

Anomie subscribed.

You shouldn't have expected this to work in the first place. Before deduplication, the output was

<style>...</style>
<div class="foo">…</div>
<style>...</style>
<div class="foo">…</div>

which wouldn't have worked with adjacent sibling selectors either. The deduplication simply changed the non-first copies of the <style> to a <link>.

If you really need to use adjacent sibling combinators for something like this, you could structure your template's output something like this instead:

<div class="foo"><templatestyles src="whatever/styles.css"/> ... </div>

There's a very slight chance of FOUC if you're applying styles to .foo itself, but unless something else is already styling the div and you're overriding that it's very unlikely it'd be possible for anyone to notice it.

If I had checked the actual implementation, and not just listening to the ads, before asking for this to be turned on, I would probably concluded that the implementation is plainly wrong.

I will inform the community that this extension probably does not do what people expect.

I have no idea what "ads" you were listening to, but you're free to make any incorrect conclusion that you wish for your own personal beliefs.

But I hope you restrict your "inform the community" to stating the facts. Specifically that the <templatestyles> tag inserts the styles as a <style> tag[1] inline at the point of use, rather than inserting nothing at all into the HTML source as you seem to have assumed.

[1]: Or a placeholder <link> if the same stylesheet is referenced more than once.

Vvjjkkii renamed this task from Templates reusing a stylesheet triggers a warning, and the warning interfers with the adjacent sibling combinator to c4caaaaaaa.Jul 1 2018, 1:10 AM
Vvjjkkii reopened this task as Open.
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot renamed this task from c4caaaaaaa to Templates reusing a stylesheet triggers a warning, and the warning interfers with the adjacent sibling combinator.Jul 2 2018, 4:18 PM
CommunityTechBot closed this task as Declined.
CommunityTechBot raised the priority of this task from High to Needs Triage.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added a subscriber: Aklapper.