Skip to content

feat: add Vite support for exported web components - #13148

Merged
Artur- merged 31 commits into
masterfrom
feat/vite/exported-web-components
Mar 11, 2022
Merged

Artur- merged 31 commits into
masterfrom
feat/vite/exported-web-components

Conversation

@vursen

@vursen vursen commented Feb 24, 2022 •

Copy link
Copy Markdown
Contributor

Description

This PR adds Vite support for exported web components making it possible to build and run them with Vite in development and production modes.

A brief overview of the differences between Webpack and Vite implementations:

Webpack:

When there is any component marked as exported, in addition to bundle-***.js, Webpack will build an export-***.js chunk that contains generated-flow-imports. The Flow client will be generated by Flow as a separate script.

Once an exported web component is requested, WebComponentBootstrapHandler is the one that is in charge of generating a bootstrap script to initialize this web component.

The current Webpack implementation of WebComponentBootstrapHandler is based on BootstrapHandler. It dynamically builds an HTML bootstrap document injecting all the scripts required for the exported web component to work to the document's head. There is where it will inject the Flow client as a separate script and the export-***.js chunk, getting it from the chunk stats file.

Eventually, the handler serializes the head of the resulting HTML document into a set of javascript instructions and sends them to the browser as a result.

Vite:

When there is any component marked as exported, Vite will build vaadin-web-component.ts and inject it to web-component.html. It is worth noting that vaadin-web-component.ts includes both generated-flow-imports and the Flow client.

For Vite, the WebComponentBootstrapHandler logic was modified so that it instead takes web-component.html as an initial bootstrap document. The bootstrap document already contains the actual link to vaadin-web-component.ts which is
injected by Vite. All the other scripts required for the exported web component to work, such as the @Push annotation script, the handler injects dynamically. An advantage of this approach is that it doesn't require any chunk stats so that it works pretty much the same way as IndexHtmlRequestHandler.

Eventually, the handler serializes the head of the resulting HTML document into a set of javascript instructions and sends them to the browser as a result.

Fixes #12298

Type of change

  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@vursen vursen changed the title feat: support building exported web components with Vite feat: add support for Vite for exported web components Feb 24, 2022
@vursen
vursen marked this pull request as draft February 24, 2022 08:12
@vursen vursen changed the title feat: add support for Vite for exported web components feat: add support for Vite for exported web components (WIP) Feb 24, 2022
@github-actions

github-actions Bot commented Feb 24, 2022 •

Copy link
Copy Markdown
Contributor

Unit Test Results

   952 files  +  4     952 suites  +4   48m 31s ⏱️ + 6m 54s
6 165 tests +  8  6 116 ✔️ +  7  49 💤 +1  0 ❌ ±0 
6 383 runs  +11  6 328 ✔️ +10  55 💤 +1  0 ❌ ±0 

Results for commit cb3b194. ± Comparison against base commit e850b28.

♻️ This comment has been updated with latest results.

protected String getBootstrapJS(JsonValue initialUIDL,
BootstrapContext context) {
boolean productionMode = context.getSession().getConfiguration()
.isProductionMode();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

NULL_DEREFERENCE: object returned by context.getSession().getConfiguration() could be null and is dereferenced at line 1255.
(at-me in a reply with help or ignore)

@vursen
vursen force-pushed the feat/vite/exported-web-components branch from f52cee0 to 2d17c21 Compare February 25, 2022 14:00
@vaadin-bot vaadin-bot added +1.0.0 and removed +0.1.0 labels Feb 25, 2022
@vursen
vursen force-pushed the feat/vite/exported-web-components branch from f874da1 to 92b934f Compare February 25, 2022 20:21
@vaadin-bot vaadin-bot added +0.1.0 and removed +1.0.0 labels Feb 25, 2022
@vursen vursen changed the title feat: add support for Vite for exported web components (WIP) feat: add Vite support for exported web components (WIP) Feb 26, 2022
@vursen vursen self-assigned this Feb 27, 2022
@vursen
vursen marked this pull request as ready for review February 27, 2022 15:16
@vursen vursen changed the title feat: add Vite support for exported web components (WIP) feat: add Vite support for exported web components Feb 27, 2022
@vursen
vursen requested review from Artur- and platosha February 27, 2022 15:19
@Artur-
Artur- requested a review from caalador March 2, 2022 09:11
@joheriks
joheriks requested a review from mcollovati March 7, 2022 12:15
@sonarqubecloud

sonarqubecloud Bot commented Mar 9, 2022

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

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
0.0% 0.0% Duplication

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 23.1.0.alpha1 and is also targeting the upcoming stable 23.1.0 version.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Vite] Embedded Web Components do not init in development mode

6 participants