-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(framework): dynamic custom elements scoping #2091
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vladitasev
requested review from
ilhan007,
MapTo0,
fifoosid,
pskelin and
MarcusNotheis
August 14, 2020 13:23
ilhan007
approved these changes
Aug 19, 2020
ilhan007
pushed a commit
that referenced
this pull request
Oct 17, 2020
ilhan007
pushed a commit
that referenced
this pull request
Nov 11, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
❗ What changes for component developers
Important information for component developers:
ui5-button-mytest
instead ofui5-button
if the application callssetCustomElementsScopingSuffix("mytest");
so we can no longer rely on the tag name.<ui5-button-mytest icon="add" ui5-button>Hello world</ui5-button-mytest>
and this attribute can be used reliably..js
files never write selectors by tag for the custom elements, only by the new attribute: f.e.❌
this.shadowRoot.querySelector("ui5-list")
✔️
this.shadowRoot.querySelector("[ui5-list]")
.css
files never write selectors by tag for the custom elements, only by the new attribute: f.e.❌
ui5-button ui5-icon {}
✔️
[ui5-button] [ui5-icon] {}
There are no changes to the way you write
.hbs
files - continue to use the tags normally, f.e.<ui5-icon>
. The template processing logic will replace the tags with the suffixed tags at runtime. However, for this to work, you should properly declare all dependencies for your component (see the next point):In
UI5Element.js
there is a newdependencies
static getter, f.e. theDatePicker.js
implementation is:Add all the component's dependencies there, instead of inside
onDefine
.dependencies
static getter when the component itself is defined, it is no longer necessary to define them manually inonDefine
.Only use
onDefine
for other resources, f.e.or
startWithScopе
that is the same asstart
, but also creates scoped bundles and scoped test pages for easier testing.Note: You should continue working with
yarn start
as before,yarn startWithScopе
is slower and creates 8 bundles instead of 4, so it is intended for use only when you are specifically testing the scoping functionalityand then:
Goal of the change
Example:
Integration scenario: on the same page 3 separately bundled and separately loaded pieces of code co-exist:
ui5-card
,ui5-button
andui5-input
tags already)The 2 libraries use scoping suffixes so they can use newer features of the
ui5-button
for example (properties such asnewButtonProp
andevenNewerButtonProp
that are not found in older versions).For applications
Applications, but mostly micro-frontend authors, have new APIs available:
that allow to scope all (or some) custom elements with the provided suffix. Then the usage becomes:
and
ui5-button
is no longer available, onlyui5-button-demo
.Components that instantiate other components in the shadow root, also use the scoping suffix transitively:
For component developers
dependencies
static getter exists on framework level that lists all components that the current component depends on. This information is used for one-time template processing at runtime to replace their tag names with the suffixed ones.onDefine
, this is now done by the framework.Changes to
lit-html
logicUntil
lit-html 2.0
is released with the support of static bindings, we are going to pre-process all strings once and replace tags by monkey-patching thehtml
andsvg
functions. For that purpose, executing templates now requires also information about the custom tags that may be found in the template (and need to be suffixed) as well as the suffix itself. The whole logic is moved to a separate module.Changes to
bundle*.js
files andpackage.json
filesmain
project'sbundle.esm.js
file is now exported and reused by all other bundles (configuration and other global functions for the test pages).main
andfiori
) now have a customui5
entry inpackage.json
. This is used by the tools to analyze which packages export UI5 Web Components.startWithScoping
command available on top level and component-package level. It is the same asstart
, but also includes 2 more bundles for each package and a new set of test pages found indist/test-resources/scoped/
(exact copy ofdist/test-resources/pages/
but with the scoped bundles and scoped tags). This also includes ascope-lint
task that scans the source files for scoping-unfriendly selectors (by tag name).closes: #2080