Page MenuHomePhabricator

Develop and document a proposal for when to use Vue/Codex
Open, LowestPublic

Description

NOTE: Design Systems is seeking feedback from other WMF teams on this topic; input greatly appreciated.

Overview

Two years have passed since the original RFC around using Vue.js in Mediawiki (T241180) was opened. Since then several teams have been able to experiment with using Vue for different features, and most feedback around the framework has been positive. Today, the Design Systems Team is working towards an initial release of a new Vue-based UI library, Codex (T299138), and a general migration from Vue 2 to Vue 3 is underway as well (T289017). Vue is clearly here to stay in the MediaWiki universe.

However, there is still a lot of uncertainty about when and where this new JavaScript framework can be used. Some things that complicate the question within our projects:

  1. Many of our projects have strict performance requirements (supporting users with older/slower mobile devices, limited bandwidth, etc)
  2. Some projects still need to support legacy browsers to varying degrees (though this is starting to change)
  3. We don't currently have a way to provide SSR capability for Vue components (though we hope to start exploring solutions here soon).

The Design Systems Team would like to develop a clear set of criteria (based in input from appropriate stakeholders) to help WMF teams and volunteers decide whether to use Vue for a particular project. And since Vue 3 drops support for IE11, this question will be closely related with the question of how new features should support users of legacy (non-ES6) browsers.

Draft Guidelines

Below are draft guidelines based on feature/product type. These likely need to be refined; please discuss below.

Off-Wiki

Example: stats.wikimedia.org

Off-wiki products represent the simplest case. Stand-alone tools that exist outside of MediaWiki are great candidates for using Vue.js. Dashboard pages that pull data from various APIs in particular can benefit greatly from being built in Vue. Such products may not need any sort of SSR at all.

Recommendation: Off-wiki projects are encouraged to use Vue 3, Codex (once released) and Vite. We also encourage teams creating new off-wiki tools to write JS code according to modern standards (ES6, ES Modules syntax, prefer native web APIs like fetch and promise over 3rd-party libraries, etc). Modern CSS layout APIs like Flexbox are also encouraged, as is the use of appropriate linter configuration.

Dedicated MediaWiki Special Page

Example: Commons MediaSearch

Dedicated MediaWiki special pages are also good candidates for Vue.js in many cases. However, since these pages live within the MediaWiki environment, some different coding practices may need to be followed.

Recommendation: Features that live on dedicated Special pages are encouraged to use Vue and Codex if it makes sense to do so. However, we recommend that teams rely on the Mediawiki-provided versions of Vue, Vuex, and the Codex component library (once it is available), rather than bundling their own copies of these dependencies via a project-specific build tool. Single-file components (aka .vue files) are supported natively in ResourceLoader but must use RL-compatible module syntax (require instead of import, etc). ES6/ES2015 syntax should be used throughout these projects (let, const, arrow functions, modern array methods, etc).

Additional Considerations: If a Special page needs to provide server-rendered content (for SEO, performance, or audience reasons), the server-rendered version of the feature needs to be defined separately in PHP. We know this is not ideal since it means double work; wherever possible, we encourage teams to rely on Mustache templates (since markup from Vue components could probably be easily adapted there). Commons MediaSearch renders a Mustache template from PHP and then replaces it with a matching client-side UI written in Vue as soon as page JS initializes. For this project, component styles were split out separately from the .vue files so that they could be re-used by server-rendered elements.

Globally-enabled Skin/Extension feature

Example: New Vector search tool, Related Articles feature

Some features are enabled globally on a given Wiki as part of a skin or extension. Search boxes and Related Articles sections appear on every page (or at least every page of a given type).

Recommendations: TBD – discuss below. Some open questions we should answer:

  • Is it acceptable to load Vue.js on pageload?
  • If not, why not? What else constitutes an appropriate "cue" to signal when to load the framework?
  • Are there any tests we need do to properly assess impact?
  • If the full build of Vue is not acceptable in this context, would a bundled/optimized build (tree-shaken, no template compiler, produced by a skin- or extension-specific build step) be acceptable? What if we shipped only the Vue runtime and somehow did just-in-time template compilation of .vue files in ResourceLoader (assuming this was feasible)?
  • What about the aggressively-optimized petite-vue (an alternative distribution of the framework). Note that this approach could not use the standard Codex UI components and would rely instead on something like a set of Mustache templates; some extra work would be required to set this up for easy usage across teams.
    1. Acceptance criteria
  • Deliver a proposal that outlines a few options for paths forward with Vue/Codex, to review with key stakeholders (DST to draft)
  • Reach a consensus on the open questions above after discussing with key stakeholders (Web Team, Performance Team, etc).
  • Publish the guidelines in an appropriate location on-wiki and share them with interested parties

Related Objects

Event Timeline

Since there have been concerns from the Performance-Team (cc @Krinkle ) regarding some Vue features (see e.g. the RelatedArticles port), I think these guidelines should also include advice from them, so that performance concerns can hopefully be identified ahead of time by the developer reading the guidelines before choosing Vue, rather than getting a -1 on Gerrit when they've already done most of the work.

Hey @Aklapper, I think this should be a subtask - there's some overlap with the contents of T279421 and this task specifically aims to provide a resource for teams considering using Vue for projects so they can evaluate what they need and if their needs are supported yet.

I think these guidelines should also include advice from [Performance], so that performance concerns can hopefully be identified ahead of time by the developer reading the guidelines before choosing Vue, rather than getting a -1 on Gerrit when they've already done most of the work.

I agree on all points and look forward to drafting this with you. I regret not noticing this earlier. Relevant points excerpted from T286835#7350845:

@Krinkle wrote:
  • It renders client-side something that causes a visible layout shift, which is something we generally try to avoid.
  • […] no performance review in our queue.
  • I recommended the same as here [in 2018].

Here's another point to consider going into this discussion.

Evan You recently released a new project called "petite vue", which is basically an alternate distribution of Vue 3 (a subset of the larger library) that is optimized for the progressive enhancement, "sprinkling in" use-case. Size is about 6KB.

For skin code and certain features, this could provide everything we need; we could save "full" vue plus the component library for situations where we need a higher level of interactivity.

I've updated this task based on today's discussion in the Design System Team's engineering meeting. I'd like to invite other interested folks to chime in on the draft "guidelines" so that we can produce something that will be useful to teams deciding how to build new features.

The question of how to deal with "global" features (things in skins, extensions that modify all Article or File pages on a wiki, etc) is going to be the trickiest one; input here greatly appreciated.

Finally, I want to acknowledge that there are many different valid perspectives on this topic and it's okay if we are not all in agreement – especially at the outset. Let's have a constructive discussion about the pros and cons of different approaches in the hopes of arriving at a good set of guidelines that will hold for most projects.

STH renamed this task from Develop and document guidelines for when to use Vue to Develop and document a proposal for when to use Vue/Codex.Feb 22 2022, 10:10 PM
STH updated the task description. (Show Details)
STH subscribed.

Thank you all for the detailed context and considerations above. I updated the task title and deliverables list to include a formal proposal for how to move forward, with special attention to performance considerations. Once we (DST/RW) have a few options outlined, we can circle back for a review and decision. I added myself as assignee for now, to coordinate efforts here.

egardner triaged this task as High priority.Mar 2 2022, 5:50 PM

Current status of this: we are developing a more complete proposal (including a full range of options) – this may become the starting point of a Technical Decision Making Process proposal (the successor to the RFC process). Once the draft is ready for wider circulation we will update the task here with the latest text.

STH lowered the priority of this task from High to Medium.Apr 25 2022, 11:34 PM

Re-opening this task because I don't think it has been adequately addressed.

Could someone elaborate what is still needed / what's the status of this task? Thanks a lot!

There are still barriers to using Vue in certain contexts e.g. mobile and on page load in desktop. This task is about clarifying how and where Vue can be used by the creation of documentation. In particular this is blocking T286835 and T281930

ldelench_wmf lowered the priority of this task from Medium to Lowest.Jan 20 2023, 7:06 PM