Page MenuHomePhabricator

[MEX] Align uses of snak value HTML vs snak HTML in Vue / PHP code
Closed, ResolvedPublic

Description

Per T396098#11020947 , we use "snakHtml" to mean two different things in the Vue / PHP code, which results in Javascript console warnings:

Inconsistent server-rendered HTML for snak with hash 3f38564928b806427a6b5654a9008e93cb73f39a:
<div class="wikibase-snakview wikibase-snakview-3f38564928b806427a6b5654a9008e93cb73f39a">
<div class="wikibase-snakview-property-container">
<div class="wikibase-snakview-property" dir="auto"><a title="Property:P280" href="/wiki1/index.php/Property:P280">lexeme property</a></div>
</div>
<div class="wikibase-snakview-value-container" dir="auto">
<div class="wikibase-snakview-typeselector"></div>
<div class="wikibase-snakview-body">
<div class="wikibase-snakview-value wikibase-snakview-variation-valuesnak"><a href="/wiki1/index.php/Lexeme:L1" title="L1: English, noun"><span lang="en">Lucas</span><span>/</span><span lang="de">Lucas</span><span>/</span><span lang="pt">Lucas</span><span>/</span><span lang="rm-puter">Lucas</span></a></div>
<div class="wikibase-snakview-indicators"></div>
</div>
</div>
</div> != <a href="/wiki1/index.php/Lexeme:L1" title="L1: English, noun"><span lang="en">Lucas</span><span>/</span><span lang="de">Lucas</span><span>/</span><span lang="pt">Lucas</span><span>/</span><span lang="rm-puter">Lucas</span></a>

We need to ensure that the snakHtml pinia store is consistently filled with the same data so that server- and client-side renderings remain consistent.

Acceptance Criteria

  • Javascript Console warnings are no longer emitted when rendering items that contain the same snak value in the main snak vs. in references / qualifiers (but the consistency check and console.log warning remain in place
  • Items render as they have been rendering

Event Timeline

Another argument for putting data value HTML, not snak HTML, in the Pinia store: that’s the only HTML we can easily get out of the API (I think). Once we add editing support, we can get HTML for a data value using wbformatvalue (after potentially parsing it with wbparsevalue), but there’s no API module that returns HTML for a full snak AFAIK.

In principle, data values also have a hash, but I’m not sure we make that available outside of Wikibase PHP code. So I think the best way forward might still be to use data value HTML, indexed by the hash of the containing snak, just with better naming to make it less confusing.

Hm, I might have misremembered something… Use Pinia store to stash server-rendered HTML already uses a SnakFormatter, not a ValueFormatter, to generate the main snak HTML. There’s still some mismatch, because this is different from the SnakHtmlGenerator introduced in Add Vue template for displaying references, but I don’t understand why one half of the HTML then just looks like a data value…

Could it be the second argument to getSnakHtml? I set $showPropertyLink to true...

I also don’t understand why this item doesn’t show the error. I’ll need to look more into this now that I’m hopefully done being sidetracked by T400245 ^^

I also don’t understand why this item doesn’t show the error.

Ah, it needs to be in a different statement. I edited the item and now it reproduces the console warning.

Hm, I might have misremembered something… Use Pinia store to stash server-rendered HTML already uses a SnakFormatter, not a ValueFormatter, to generate the main snak HTML. There’s still some mismatch, because this is different from the SnakHtmlGenerator introduced in Add Vue template for displaying references, but I don’t understand why one half of the HTML then just looks like a data value…

This is just more confusing terminology in Wikibase. The SnakFormatter interface is responsible for formatting the non-property parts of a snak, i.e. most of the time, the value (though this is also the part that formats “unknown value” and “no value” using interface messages). Then SnakHtmlGenerator wraps that to add the rest of the snak HTML, including the property link. I believe we want the SnakFormatter part.

Also, just to write it down, here’s what the SnakFormatter looks like at runtime:

An ErrorHandlingSnakFormatter wrapping a DispatchingSnakFormatter whose formattersByDataType are an HtmlExternalIdentifierFormatter for PT:external-id, and a PropertyValueSnakFormatter wrapping a DispatchingValueFormatter for everything else; the DispatchingSnakFormatter’s formattersBySnakType are two MessageSnakFormatters for novalue and somevalue; the ErrorHandlingSnakFormatter’s fallbackFormatter is a DispatchingValueFormatter

So the only special cases compared to a normal ValueFormatter are: two MessageSnakFormatters, for somevalue/novalue; and an HtmlExternalIdentifierFormatter, for formatting external identifiers whose properties have a formatter URL as hyperlinks (this can’t happen at the ValueFormatter level because the property isn’t available there).

Change #1172068 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Clarify SnakFormatter output

https://gerrit.wikimedia.org/r/1172068

Change #1172069 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] WIP: Align uses of snak / data value HTML

https://gerrit.wikimedia.org/r/1172069

Change #1172068 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Clarify SnakFormatter output

https://gerrit.wikimedia.org/r/1172068

Sorry, this isn’t ready for peer review yet – I’m still working on the first patch in the chain.

Alright, now I think it should be ready for peer review. (Might need a few more patch sets to make linters happy, we’ll see.)

Change #1174478 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Make propertyName component contain only non-block elements

https://gerrit.wikimedia.org/r/1174478

Change #1172069 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Align uses of snak / data value HTML

https://gerrit.wikimedia.org/r/1172069

Change #1174478 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Make propertyName component contain only non-block elements

https://gerrit.wikimedia.org/r/1174478

Change #1176229 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/extensions/Wikibase@master] Add phpunit test for wbui2025 statement sections

https://gerrit.wikimedia.org/r/1176229