Skip to content

DO NOT MERGE: first experimental prototype of Lit based versions - #5301

Closed
web-padawan wants to merge 3 commits into
mainfrom
wip/lit-2023
Closed

web-padawan wants to merge 3 commits into
mainfrom
wip/lit-2023

Conversation

@web-padawan

@web-padawan web-padawan commented Jan 13, 2023 •

Copy link
Copy Markdown
Member

Description

TL;DR: this is not our first step towards moving to Lit - but now it's an attempt to get it done.

Warning
This PR is a personal initiative, not something currently planned by the team to work on.
It is intended to be a discussion opener rather than a ready to use implementation.

Type of change

  • Prototype

Background

There has been a discussion on Vaadin Discord server recently about our plans to remove Polymer in 2023.
This is a very long-lasting idea that I've been trying to pursue since 2018 - which is almost 5 years now:

  1. Even before Lit 1.0 was out, I already started prototyping the lit-components project using 0.x in May 2018;
  2. One year later, in November 2019, I published the blog post at https://vaadin.com outlining some rough plans;
  3. That concluded with a component-mixins research project - most of its code is now incorporated to this repo;
  4. We released a few incomplete alphas for 7 web components, but realised the complexity of remaining effort.
  5. Next step was to remove most of usage of Polymer in Vaadin components - see this list of issues and PRs;
  6. Another project that took some time was adding Lit directives for components that support renderer function;
  7. Then I created PolylitMixin - first, as as personal project. Later we moved it to this repo and improved logic;
  8. We also added Lit support for some mixins, namely ThemableMixin, DirMixin and other mixins / controllers;
  9. Finally, we added lit-html usage to vaadin-upload, vaadin-avatar-group and vaadin-message-list.

That said, we still don't have any web component that extends LitElement and people are disappointed about it.
This PR proposes one possible solution for moving forward with Lit support without exposing it publicly (yet).

Proposal

  1. For each component, extract logic into a mixin. Existing examples: ButtonMixin, ItemMixin, ProgressMixin etc.
  2. Move component core styles from <style> tag inside the template to a css tagged literal from the lit package;
  3. Add new base classes for Lit versions e.g src/vaadin-lit-button.js using the same vaadin-button tag name;
  4. Update existing classes to use new mixins / styles, while keeping all the JSDoc comments / TS definitions untouched;
  5. Update unit tests to cover both original base classes (Polymer-based) and new experimental classes (Lit-based);
  6. Exclude new files like src/vaadin-lit-button.js from "files" in package.json to NOT publish them to npm.

Components

Currently, this PR covers the following web components as an illustration of the suggested approach:

  • vaadin-details
  • vaadin-item
  • vaadin-radio-button

I'm planning to gradually update this PR with adding more simple components, and rebase as necessary.
This is going to be my main focus for "Community Friday" at Vaadin (every two weeks including today).

Some complex components are not supposed to be covered by this PR:

  • vaadin-date-picker is only partially converted to Lit - see the WIP branch with two updated components;
  • vaadin-grid, vaadin-grid-pro and vaadin-crud were converted by @tomivirkki in this branch.

Next Steps

We are going to have a meeting to clarify our plans related to web components Lit conversion in early February.
So we'll discuss this within a team and decide what to do next. Then we will hopefully share more updates.

10.02 Update

The following experiments have been merged to main and 24.0 branches and this PR is now updated:

@web-padawan
web-padawan force-pushed the wip/lit-2023 branch 7 times, most recently from d89d288 to 18a0fc3 Compare January 14, 2023 09:40
import { buttonStyles } from './vaadin-button-styles.js';

/**
* LitElement based version of `<vaadin-button>` web component.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not source code related, but wanted to create discussion without endless comments within the main PR about one topic.

Something to consider from an outsiders perspective: As far as I understand the codebase and communication to the community, all usage of Lit element instead of polymer is a internal detail thanks to the removal of the public API, allowing to gradually do this within minor releases(?). Otherwise it could literally take years to get this on the road, looking at the public available comments that with the new and simplified release model of the platform the amount of major releases should be reduced. Vaadin 24 had to be pushed because of external factors like the Jakarta Namespace and Spring Boot / ecosystem end of life. I (hopefully) don't see any other big problem in the next 1 or even 2 years justifying another major release - which in turn would move this change (if it has to be done within a major release) to like 2024/2025.. leaving us/you with three options:

  • pushing at least some components to lit in 24 to get early Feedback like components as button, layouts and non-complex stuff and gradually move the others afterwards in minors to come (with the experience you get from Feedback of 24.0's components)
  • doing all of this within minor versions of 24.x
  • Having this transformation wait for the next big release (25.0) with no definitive timeline

With the official removal / payed support of PolymerTemplate in flow for 24.0 - I think it would be the perfect timing to get this done / on the road.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What knoobie said.

And also, what and where and who can I pay to increase velocity on this?

I've already talked to my team JS wizard @anoblet about contributing some of our time here, but we could find more budget.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your opinions! This is exactly the kind of discussion that I'd like to have.

all usage of Lit element instead of polymer is a internal detail thanks to the removal of the public API, allowing to gradually do this within minor releases(?). Otherwise it could literally take years to get this on the road

Yes, this is what the original plan was back in the day, described in the blog post from 2019 that I linked above.
I totally agree that from Java / Flow developer's point of view, these changes are purely internal refactorings.

However, we also need to consider Hilla and web components users who build their applications with Lit.
As now when we have React wrappers, not breaking them is also something that we have to consider.

Essentially, changing the library used under the hood is a behavior altering change, because of switching from sync DOM rendering / updates (Polymer) to async (Lit) - see my additions of await nextFrame() in unit tests.

Overall, I feel like this change is long overdue. We definitely shouldn't postpone it till 2024 or further.

@web-padawan
web-padawan force-pushed the wip/lit-2023 branch 5 times, most recently from 303e794 to f7b4649 Compare January 18, 2023 18:48
@web-padawan
web-padawan force-pushed the wip/lit-2023 branch 5 times, most recently from 17c3b92 to 9798001 Compare February 5, 2023 12:47
@lkraav

lkraav commented Feb 5, 2023

Copy link
Copy Markdown
Contributor

Are these drop-in compatible with their Polymer cousins? Testable in current Vaadin 23 or 24-based Storybooks and apps?

@web-padawan

Copy link
Copy Markdown
Member Author

Are these drop-in compatible with their Polymer cousins?

The idea is to achieve it where possible. As discussed with @vursen we might even want to implement some mechanism for Polymer-style sync rendering, even if that would mean extra complexity. However, there is no decision on this yet.

@lkraav

lkraav commented Feb 10, 2023

Copy link
Copy Markdown
Contributor

I saw merges into 24.0 branch? Some kind of official experimentation strategy got decided?

@web-padawan

Copy link
Copy Markdown
Member Author

I saw merges into 24.0 branch? Some kind of official experimentation strategy got decided?

We agreed to proceed with necessary refactorings, like extracting reusable mixins, template and CSS literals.
For now, this will be done as part of maintenance. The goal is to gradually reduce our tentative estimates.

On top of that, I'll be spending 10% of time on Lit conversion (every second Friday starting from today).
@tomivirkki proposed his help with reviews, and we agreed that other team members will keep an eye.

Please note, we still have no ETA on when the full Lit conversion will be actually delivered by the team.
Finalizing it and converting the most complicated components would require a dedicated project.

There's a chance that this will be mostly done during the summer, so my target is Q3-Q4 this year.

@lkraav

lkraav commented Feb 11, 2023

Copy link
Copy Markdown
Contributor

Please note, we still have no ETA on when the full Lit conversion will be actually delivered by the team.
Finalizing it and converting the most complicated components would require a dedicated project.

There's a chance that this will be mostly done during the summer, so my target is Q3-Q4 this year.

Sounds awesome. Accordion and Context Menu I think would enable us 100% Lit!

@lkraav

lkraav commented Feb 12, 2023

Copy link
Copy Markdown
Contributor

We agreed to proceed with necessary refactorings, like extracting reusable mixins, template and CSS literals.
For now, this will be done as part of maintenance. The goal is to gradually reduce our tentative estimates.

How would I go about testing this on my package - does this PR #5301 branch wip/lit-2023 remain as the single source of truth - or should I pull some "passed basic QA" branch, like V24, or... @web-padawan?

@web-padawan

Copy link
Copy Markdown
Member Author

@lkraav No, this PR is going to be closed after all the prototypes are merged. It was just a discussion opener. From now on, all the experiments will be merged to the main branch.

@lkraav

lkraav commented Feb 12, 2023

Copy link
Copy Markdown
Contributor

No, this PR is going to be closed after all the prototypes are merged. It was just a discussion opener. From now on, all the experiments will be merged to the main branch.

Aha, looking closer at one of the merged PRs, it looks like they will co-exist for however long, and I will need to specifically import the Lit version.

I'm a bit unclear on how I replace my package.json dependencies for this, for example @vaadin/progress-bar: ^23.3.6 is pointed to main git branch how?

@sonarqubecloud

Copy link
Copy Markdown

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
8.0% 8.0% Duplication

@web-padawan

Copy link
Copy Markdown
Member Author

Closing this PR as stale. We have added a bunch of Lit based component versions (still not published to npm for now).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants