Skip to content

Commit

Permalink
web: upgrade to Lit3
Browse files Browse the repository at this point in the history
This commit replaces our Lit2 implementation with a Lit3 implementation.

This upgrade required two major shifts within our code, both of them consequential.

First, the restructuring of the way the get/set decorators for properties and states meant that a
lot of the code we were using needed to be refactored. More than that, a lot of those custom
accessors were implemented to trigger side-effects, such as when a providerID is set or changed
triggering the ProviderView to fetch the requsted Provider. The Lit2 and Lit3 documentation both say
[there is a better way to handle
this](https://lit.dev/docs/v2/components/properties/#:~:text=In%20most%20cases%2C%20you%20do%20not%20need%20to%20create%20custom%20property%20accessors)
by detecting the change in the `willUpdate()` point of an elements Lifecycle and triggering the side
effect there instead. I've done this in several places with a pattern of detecting the change, and
then naming the corresponding change as `fetchRequestedThing()`. The resulting code is cleaner and
uses fewer controversial features.

The other is that the type signature for `LitElement.createRenderRoot()` has changed to be either an
HTMLElement or a DocumentFragment. This required some serious refactoring of type changes through
Base and Interface codes. Noteably, the custom `AdoptedStyleSheetsElement` interface has been
superseded by the supplied and standardized
[DocumentOrShadowRoot](https://github.com/microsoft/TypeScript/blob/aa2b2352e1d506bf26b6423b74c61e45a63b4ea5/src/lib/dom.generated.d.ts#L4715)
interface. Unfortunately, that interface is a mixin, and casting or instance checking are still in
place to make sure the objects being manipulated are typed "correctly."

Three files I touched during the course of this triggered SonarJS, so there are some minor fixes,
replacing some awkward syntax with more idiomatic code.  These are very minor, such as replacing:

```
const result = someFunction();
return result;

/* with */

return someFunction();

```

and

```
const result = x();
if (!result) { return true } else { return false }

/* with */

return !x();

```
  • Loading branch information
kensternberg-authentik committed Mar 1, 2024
1 parent 8cf594b commit b0481b3
Show file tree
Hide file tree
Showing 33 changed files with 425 additions and 359 deletions.
212 changes: 130 additions & 82 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
"@formatjs/intl-listformat": "^7.5.5",
"@fortawesome/fontawesome-free": "^6.5.1",
"@goauthentik/api": "^2024.2.1-1709222007",
"@lit-labs/context": "^0.4.0",
"@lit-labs/task": "^3.1.0",
"@lit/localize": "^0.11.4",
"@lit/reactive-element": "^2.0.4",
"@lit/context": "^1.1.0",
"@lit/localize": "^0.12.1",
"@open-wc/lit-helpers": "^0.7.0",
"@patternfly/elements": "^2.4.0",
"@patternfly/patternfly": "^4.224.2",
Expand All @@ -56,7 +57,7 @@
"country-flag-icons": "^1.5.9",
"fuse.js": "^7.0.0",
"guacamole-common-js": "^1.5.0",
"lit": "^2.8.0",
"lit": "^3.1.2",
"md-front-matter": "^1.0.4",
"mermaid": "^10.8.0",
"rapidoc": "^9.3.4",
Expand Down
Loading

0 comments on commit b0481b3

Please sign in to comment.