Page MenuHomePhabricator

[Spike] Investigate lead paragraph hoisting on mobile with parsoid enabled
Closed, ResolvedPublic2 Estimated Story Points

Description

Background

Currently, lead paragraphs are not being correctly displayed before infobox content - in order to unblock work on T359002, we should first understand the current issue and best recommendation for how to fix it

User story

As a developer on the web team, I would like to be able to display the lead paragraph first while understanding the technical implications of doing so and having confidence in my implementation

Requirements

  • the current implementation is well-understood, including why parsoid is failing
  • We have evaluated T262093 and the problem it attempted to solve
  • We have evaluated how the existing transform impacts performance and how to minimize this in the new version
  • The discussion in T359002 is factored into consideration
  • a recommendation is made, ideally with a rough proof of concept, for how to solve this going forward for parsoid

Acceptance criteria

  • we feel that we have enough information to unstall T359002

Rollback plan

N/A - nothing should be merged as part of this spike

Event Timeline

Jdlrobson triaged this task as Medium priority.Jun 3 2024, 5:22 PM
SToyofuku-WMF added subscribers: ovasileva, Jdlrobson.

Moving to ready for development as I believe it's important for this to be done this sprint, but feel free to move it if I'm disrupting anything @ovasileva @Jdlrobson !!

Putting down for now to wrap up higher priority night mode tickets first

Proposal for Reordering Elements in Mobile View

Objective:
To reorder elements within the MediaWiki section with data-mw-section-id=0 for mobile view, ensuring that the element with the ID #mwDg appears (usually the lead paragraph?) before the infobox element.

Current HTML Structure:

html
<div data-mw-section-id="0">
    <table>Infobox</table>
    <div id="mwDg">Lead Paragraph</div>
</div>

Proposed CSS Solution:

The following CSS solution uses Flexbox to reorder the elements in mobile view without changing the HTML structure.

  1. CSS Implementation:

/* Media query for mobile view */
@media (max-width: 768px) {
    [data-mw-section-id="0"] {
        flex-direction: column-reverse; /* Reverse the stacking order for mobile */
    }

    #mwDg {
        order: 1; /* Change order for mobile view */
    }

    [data-mw-section-id="0"] > table {
        order: 2; /* Change order for mobile view */
    }
}

Explanation:

  • Flexbox Layout: The data-mw-section-id="0" container is set to use Flexbox with a vertical layout (flex-direction: column). This stacks the child elements (i.e., #mwDg and <table>) vertically by default.
  • Order Property: The order property is used to define the visual order of the elements within the Flexbox container.

Screenshot 2024-07-12 at 3.21.03 PM.png (1×2 px, 1 MB)

Screenshot 2024-07-12 at 3.21.46 PM.png (1×2 px, 673 KB)

@Jdlrobson Just want to check if something like this has any obvious limitations that I am not seeing such as how consistent is the selector class/id for the lead paragraph and where the style rules would have to be, whether core or in Minerva, before creating the patch.
cc: @SToyofuku-WMF

Proposal for Reordering Elements in Mobile View

Objective:
To reorder elements within the MediaWiki section with data-mw-section-id=0 for mobile view, ensuring that the element with the ID #mwDg appears (usually the lead paragraph?) before the infobox element.

Current HTML Structure:

html
<div data-mw-section-id="0">
    <table>Infobox</table>
    <div id="mwDg">Lead Paragraph</div>
</div>

Proposed CSS Solution:

The following CSS solution uses Flexbox to reorder the elements in mobile view without changing the HTML structure.

  1. CSS Implementation:

/* Media query for mobile view */
@media (max-width: 768px) {
    [data-mw-section-id="0"] {
        flex-direction: column-reverse; /* Reverse the stacking order for mobile */
    }

    #mwDg {
        order: 1; /* Change order for mobile view */
    }

    [data-mw-section-id="0"] > table {
        order: 2; /* Change order for mobile view */
    }
}

Explanation:

  • Flexbox Layout: The data-mw-section-id="0" container is set to use Flexbox with a vertical layout (flex-direction: column). This stacks the child elements (i.e., #mwDg and <table>) vertically by default.
  • Order Property: The order property is used to define the visual order of the elements within the Flexbox container.

Screenshot 2024-07-12 at 3.21.03 PM.png (1×2 px, 1 MB)

Screenshot 2024-07-12 at 3.21.46 PM.png (1×2 px, 673 KB)

I don't think the CSS approach here will always work... #mwDg is a unique ID so won't apply to all elements. Applying order to tables, will reorder them to end of the lead paragraph and would jumble the content. For a CSS approach like this to work at minimum the lead paragraph itself would need to have a class on it. Then the following might work...

[data-mw-section-id="0"] {
    display: flex;
    flex-direction: column;
}
[data-mw-section-id="0"]  > * {
   order: 2;
}
[data-mw-section-id="0"]  > p:not(.mw-empty-elt):first-of-type,
[data-mw-section-id="0"]  > .hatnote {
   order: 1;
}

It currently won't work until https://gerrit.wikimedia.org/r/c/mediawiki/services/parsoid/+/1054950 is resolved.

Okay I propose we attempt a CSS only solution first.
I've proposed https://phabricator.wikimedia.org/T359002 - let's estimate that ticket and if we get a successful estimation we can move this to sign off.

Okay I propose we attempt a CSS only solution first.
I've proposed https://phabricator.wikimedia.org/T359002 - let's estimate that ticket and if we get a successful estimation we can move this to sign off.

Moving to signoff as we have an estimate on T359002: Lead paragraph is not hoisted in new Parsoid HTML - reimplement CSS only solution