Skip to content

refactor: rename theme property to _theme, deprecate theme - #3529

Merged
vursen merged 5 commits into
masterfrom
refactor/rename-theme-to-_theme
Mar 11, 2022
Merged

vursen merged 5 commits into
masterfrom
refactor/rename-theme-to-_theme

Conversation

@vursen

@vursen vursen commented Mar 8, 2022 •

Copy link
Copy Markdown
Contributor

Description

The PR fixes the issue where it was not possible to set a theme for the web components in Svelte and Vue.

A little background, by design ThemePropertyMixin allows specifying themes only via the theme attribute. However, since ThemePropertyMixin also defines a protected read-only property theme, it makes both Svelte and Vue consider that the theme attribute must be set via that property, which doesn't work because the property is read-only. In order to fix that, we need to rename the theme property to something else so that it won't interfere with the theme attribute and therefore Svelte and Vue will treat them separately and set the theme directly via the attribute as it is supposed to work. Based on the rule that every protected method should start with _ , the correct naming will be _theme.

  • Renamed the theme property to _theme everywhere it is used internally.
  • Added a theme setter and getter which are deprecated and will be dropped in Vaadin 24. They are simply a setter and getter for the theme attribute. The deprecated theme property is supposed to be used by Svelte and Vue for the time being.

Why no deprecation warning was added?

There was a discussion about whether to show a deprecation warning in the browser console on the first call of the theme setter. The warning might be something like this:

The theme property is not supposed for public use and will be dropped in Vaadin 24. Please use the theme attribute instead.

However, this warning may also pop up in the case a web component is used in Svelte or Vue. They implicitly set the theme property instead of the theme attribute and the warning will look very confusing as the user can't really fix the problem the warning is complaining about.

What about Flow counterparts?

I didn't find any Flow counterpart manipulating the theme property directly. They all appear to use the theme attribute so everything should be okay in that regard.

There is the MenuBar component though that has a private _theme property that can now possibly interfere with the web component's _theme property. Although IT tests are not failing, I would rather rename it to __theme which is how we usually name private properties:

https://github.com/vaadin/flow-components/blob/9615db2466baf55cb86c90f9e71aa294d47fd9df/vaadin-context-menu-flow-parent/vaadin-context-menu-flow/src/main/java/com/vaadin/flow/component/contextmenu/MenuItemBase.java#L50-L52

Fixes #3483

Type of change

  • Refactor

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/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 force-pushed the refactor/rename-theme-to-_theme branch from 542a811 to bf655bc Compare March 9, 2022 07:17
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
@vursen
vursen force-pushed the refactor/rename-theme-to-_theme branch from bf655bc to 776c78c Compare March 9, 2022 07:17
@vursen vursen mentioned this pull request Mar 9, 2022
5 tasks done
@vursen
vursen marked this pull request as ready for review March 9, 2022 12:38
@vursen
vursen requested review from tomivirkki and web-padawan March 9, 2022 12:51
@vursen vursen changed the title refactor: deprecate and rename theme property to _theme refactor: rename theme property to _theme, deprecate theme Mar 9, 2022
@vursen vursen assigned tomivirkki and unassigned tomivirkki Mar 9, 2022
@vursen
vursen force-pushed the refactor/rename-theme-to-_theme branch from 3ad0b41 to e9790a8 Compare March 10, 2022 15:10
@sonarqubecloud

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 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vursen
vursen requested a review from tomivirkki March 11, 2022 07:52
@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.

Svelte, Vue 3 : Primary button ignores theme attribute

4 participants