Skip to content
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

web: upgrade to lit 3 #8781

Merged
merged 19 commits into from
Mar 11, 2024
Merged

web: upgrade to lit 3 #8781

merged 19 commits into from
Mar 11, 2024

Conversation

kensternberg-authentik
Copy link
Contributor

Details

web: upgrade to Lit3

This commit replaces our Lit2 implementation with a Lit3 implementation. This commit is built on top of the ESBuild commit, and is compatible with it.

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 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 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.”

In keeping with the current recommendation, I'm leaving the experimental Typescript decorator transformer as-is, as ESBuild does not yet have a fix for handling "standard" decorators.

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();

REPLACE ME


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make website)

This commit replaces rollup with esbuild.

The biggest fix was to alter the way CSS is imported into our system;
esbuild delivers it to the browser as text, rather than as a bundle
with metadata that, frankly, we never use.  ESBuild will bundle the
CSS for us just fine, and interpreting those strings *as* CSS turned
out to be a small hurdle.  Code has been added to AKElement and
Interface to ensure that all CSS referenced by an element has been
converted to a Browser CSSStyleSheet before being presented to the
browser.

A similar fix has been provided for the markdown imports.  The
biggest headache there was that the re-arrangement of our documentation
broke Jen's existing parser for fixing relative links.  I've provided
a corresponding hack that provides the necessary detail, but since
the Markdown is being presented to the browser as text, we have to
provide a hint in the markdown component for where any relative
links should go, and we're importing and processing the markdown
at runtime.  This doesn't seem to be a big performance hit.

The entire build process is driven by the new build script, `build.mjs`,
which starts the esbuild process as a service connected to the build
script and then runs the commands sent to it as fast as possible.
The biggest "hack" in it is actually the replacement for rollup's
`rollup-copy-plugin`, which is clever enough I'm surprised it doesn't
exist as a standalone file-copy package in its own right.

I've also used a filesystem watch library to encode a "watcher"
mechanism into the build script.  `node build.mjs --watch` will
work on MacOS; I haven't tested it elsewhere, at least not yet.

`node build.mjs --proxy` does what the old rollup.proxy.js script
did.

The savings are substantial.  It takes less than two seconds to build
the whole UI, a huge savings off the older ~45-50 seconds I routinely
saw on my old Mac.  It's also about 9% smaller.

The trade-offs appear to be small: processing the CSS as StyleSheets,
and the Markdown as HTML, at run-time is a small performance hit,
but I didn't notice it in amongst everything else the UI does as
it starts up.

Manual chunking is gone; esbuild's support for that is quite difficult
to get right compared to Rollup's, although there's been a bit of
yelling at ESbuild over it.  Codemirror is built into its own chunk;
it's just not _named_ distinctly anymore.

The one thing I haven't been able to test yet is whether or not the
polyfills and runtim shims work as expected on older browsers.
* main: (75 commits)
  Add missing commas, correction of spelling errors (#8680)
  website/docs: Add documentation for Glitchtip (#8182)
  website: add solve gitea group does not take effect (#8413)
  enterprise: fix read_only activating when no license is installed (#8697)
  core: fix blueprint export (#8695)
  web: bump the sentry group in /web with 1 update (#8687)
  web: bump yaml from 2.3.4 to 2.4.0 in /web (#8689)
  web: bump the eslint group in /web with 1 update (#8688)
  core: bump pytest from 8.0.1 to 8.0.2 (#8693)
  website: bump @types/react from 18.2.57 to 18.2.58 in /website (#8690)
  web: bump the eslint group in /tests/wdio with 1 update (#8691)
  core: bump sentry-sdk from 1.40.4 to 1.40.5 (#8692)
  core: bump coverage from 7.4.1 to 7.4.3 (#8694)
  providers/oauth2: fix inconsistent `sub` value when setting via mapping (#8677)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh_CN (#8678)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh-Hans (#8679)
  core, web: update translations (#8672)
  root: fix config loading after refactor during ruff migration (#8674)
  root: early spring clean for linting (#8498)
  website/integrations: multiple integration edits (#7923)
  ...
This commit introduces a couple of fixes enabled by esbuild and other
features.

1. build-locales

`build-locales` is a new NodeJS script in the `./scripts` folder
that does pretty much what it says in the name: it translates Xliff
files into `.ts` files.  It has two DevExp advantages over the old
build system.

First, it will check the build times of the xlf files and
their ts equivalents, and will only run the actual build-locales
command if the XLF files are newer than their TS equivalents.

Second, it captures the stderr output from the build-locales command
and summarizes it.  Instead of the thousands of lines of "this
string has no translation equivalent," now it just reports the
number of missed translations per locale.

2. check-spelling

This is a simple wrapper around the `codespell` command, mostly
just to reduce the visual clutter of `package.json`, but also to
permit it to run just about anywhere without needed hard-coded
paths to the dictionaries, using a fairly classic trick with git.

3. pseudolocalize and import-maps

These scripts were in TypeScript, but for our purposes I've
saved their constructed equivalents instead.  This saves on
visual clutter in the `package.json` script, and reduced the
time they have to run during full builds.  They're small enough
I feel confident they won't need too much looking over.

Also, two lint bugs in Markdown.ts have been fixed.
* main: (26 commits)
  stages/authenticator_webauthn: fix error when enrolling new device (#8738)
  website/docs: s3: fix migration docs (#8735)
  providers/oauth2: fix offline_access requests when prompt doesn't include consent (#8731)
  ci: fix missing DOCKER_USERNAME secret (#8730)
  website: post-split cleanup (#8729)
  website: bump @types/react from 18.2.58 to 18.2.60 in /website (#8714)
  core: bump pydantic from 2.6.1 to 2.6.3 (#8715)
  core: bump sentry-sdk from 1.40.5 to 1.40.6 (#8716)
  web: bump the sentry group in /web with 1 update (#8717)
  web: bump style-mod from 4.1.0 to 4.1.1 in /web (#8718)
  core: bump github.com/go-openapi/strfmt from 0.22.0 to 0.22.1 (#8719)
  core: bump github.com/prometheus/client_golang from 1.18.0 to 1.19.0 (#8720)
  root: fix container build (#8727)
  website/docs: s3: fix environment variables (#8722)
  enterprise: force license usage update after change to license (#8723)
  ci: do not push docker image if fork (#8724)
  translate: Updates for file web/xliff/en.xlf in fr (#8710)
  website/integrations: add documentation for OIDC setup with Paperless-ngx (#8538)
  translate: Updates for file web/xliff/en.xlf in zh_CN (#8705)
  translate: Updates for file web/xliff/en.xlf in zh-Hans (#8706)
  ...
* main:
  web: bump API Client version (#8753)
  sources/oauth: add gitlab type [AUTH-323] (#8195)
  web: bump the babel group in /web with 4 updates (#8744)
  web: bump @types/grecaptcha from 3.0.7 to 3.0.8 in /web (#8745)
  web: bump chart.js from 4.4.1 to 4.4.2 in /web (#8746)
  web: bump chromedriver from 122.0.3 to 122.0.4 in /tests/wdio (#8747)
  core, web: update translations (#8743)
  ci: fix missing output on composite action (#8741)
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();

```
Copy link

netlify bot commented Mar 1, 2024

Deploy Preview for authentik-docs canceled.

Name Link
🔨 Latest commit 182c02d
🔍 Latest deploy log https://app.netlify.com/sites/authentik-docs/deploys/65ef4050922537000899422d

Copy link

netlify bot commented Mar 1, 2024

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 182c02d
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/65ef4050a2ee5c0008ca3ab1
😎 Deploy Preview https://deploy-preview-8781--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kensternberg-authentik kensternberg-authentik changed the base branch from main to web/replace-rollup-with-esbuild March 1, 2024 23:15
@kensternberg-authentik kensternberg-authentik marked this pull request as ready for review March 1, 2024 23:18
@kensternberg-authentik kensternberg-authentik requested a review from a team as a code owner March 1, 2024 23:18
* main:
  website/docs: installation: kubernetes: fix values (#8783)
  web: bump the wdio group in /tests/wdio with 4 updates (#8789)
  core: bump github.com/stretchr/testify from 1.8.4 to 1.9.0 (#8790)
  core: bump twisted from 23.10.0 to 24.3.0 (#8788)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh_CN (#8778)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh-Hans (#8779)
  root: ensure consistent install_id (#8775)
  web: bump the sentry group in /web with 1 update (#8762)
  web: bump style-mod from 4.1.1 to 4.1.2 in /web (#8763)
  website: bump @types/react from 18.2.60 to 18.2.61 in /website (#8764)
  core: bump goauthentik.io/api/v3 from 3.2024021.2 to 3.2024021.3 (#8765)
  core: bump ruff from 0.2.2 to 0.3.0 (#8766)
  core: bump twilio from 8.13.0 to 9.0.0 (#8767)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in fr (#8774)
  core, web: update translations (#8759)
  web/admin: don't mark LDAP group property mappings as required (#8772)
  website/docs: move Applications docs up a level, other edits (#8712)
  web/admin: don't mark property mappings as required anywhere (#8752)
  website: redirect root to /docs (#8754)
* web/replace-rollup-with-esbuild:
  website/docs: installation: kubernetes: fix values (#8783)
  web: bump the wdio group in /tests/wdio with 4 updates (#8789)
  core: bump github.com/stretchr/testify from 1.8.4 to 1.9.0 (#8790)
  core: bump twisted from 23.10.0 to 24.3.0 (#8788)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh_CN (#8778)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh-Hans (#8779)
  root: ensure consistent install_id (#8775)
  web: bump the sentry group in /web with 1 update (#8762)
  web: bump style-mod from 4.1.1 to 4.1.2 in /web (#8763)
  website: bump @types/react from 18.2.60 to 18.2.61 in /website (#8764)
  core: bump goauthentik.io/api/v3 from 3.2024021.2 to 3.2024021.3 (#8765)
  core: bump ruff from 0.2.2 to 0.3.0 (#8766)
  core: bump twilio from 8.13.0 to 9.0.0 (#8767)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in fr (#8774)
  core, web: update translations (#8759)
  web/admin: don't mark LDAP group property mappings as required (#8772)
  website/docs: move Applications docs up a level, other edits (#8712)
  web/admin: don't mark property mappings as required anywhere (#8752)
  website: redirect root to /docs (#8754)
* main:
  website: fix missing compose file (#8809)
  core: bump django from 5.0.2 to 5.0.3 (#8808)
  core: bump github.com/go-openapi/strfmt from 0.22.1 to 0.22.2 (#8801)
  core, web: update translations (#8800)
  core: bump goauthentik.io/api/v3 from 3.2024021.3 to 3.2024022.1 (#8802)
  core: bump golang.org/x/oauth2 from 0.17.0 to 0.18.0 (#8803)
  core: bump github.com/go-openapi/runtime from 0.27.1 to 0.27.2 (#8804)
  website: bump @types/react from 18.2.61 to 18.2.62 in /website (#8805)
  web: bump the eslint group in /tests/wdio with 2 updates (#8806)
  web: bump the eslint group in /web with 2 updates (#8807)
  website/integrations: fix typo in proxmox docs (#8791)
  web: bump API Client version (#8797)
  release: 2024.2.2
  website/docs: prepare 2024.2.2 release notes (#8782)
  flows: fix mismatched redirect behaviour for invalid and valid flows (#8794)
  providers/oauth2: fix validation ordering (#8793)
  web: clean up UserInterface in prep for OAuth and Silo Projects (#8278)
* web/replace-rollup-with-esbuild:
  website: fix missing compose file (#8809)
  core: bump django from 5.0.2 to 5.0.3 (#8808)
  core: bump github.com/go-openapi/strfmt from 0.22.1 to 0.22.2 (#8801)
  core, web: update translations (#8800)
  core: bump goauthentik.io/api/v3 from 3.2024021.3 to 3.2024022.1 (#8802)
  core: bump golang.org/x/oauth2 from 0.17.0 to 0.18.0 (#8803)
  core: bump github.com/go-openapi/runtime from 0.27.1 to 0.27.2 (#8804)
  website: bump @types/react from 18.2.61 to 18.2.62 in /website (#8805)
  web: bump the eslint group in /tests/wdio with 2 updates (#8806)
  web: bump the eslint group in /web with 2 updates (#8807)
  website/integrations: fix typo in proxmox docs (#8791)
  web: bump API Client version (#8797)
  release: 2024.2.2
  website/docs: prepare 2024.2.2 release notes (#8782)
  flows: fix mismatched redirect behaviour for invalid and valid flows (#8794)
  providers/oauth2: fix validation ordering (#8793)
  web: clean up UserInterface in prep for OAuth and Silo Projects (#8278)
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Base automatically changed from web/replace-rollup-with-esbuild to main March 7, 2024 18:07
Signed-off-by: Jens Langhammer <jens@goauthentik.io>

# Conflicts:
#	web/build.mjs
#	web/package-lock.json
#	web/package.json
#	web/src/admin/applications/ApplicationListPage.ts
#	web/src/elements/Base.ts
#	web/src/elements/Markdown.ts
@BeryJu BeryJu changed the title Web: upgrade to lit 3 web: upgrade to lit 3 Mar 8, 2024
Copy link
Contributor

github-actions bot commented Mar 8, 2024

authentik PR Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-ghcr.io/goauthentik/dev-server:gh-182c02d6569ab45bce68ac10d6bdd70a4920bcc5
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

For arm64, use these values:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-ghcr.io/goauthentik/dev-server:gh-182c02d6569ab45bce68ac10d6bdd70a4920bcc5-arm64
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
image:
    repository: ghcr.io/goauthentik/dev-server
    tag: gh-ghcr.io/goauthentik/dev-server:gh-182c02d6569ab45bce68ac10d6bdd70a4920bcc5

For arm64, use these values:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
image:
    repository: ghcr.io/goauthentik/dev-server
    tag: gh-ghcr.io/goauthentik/dev-server:gh-182c02d6569ab45bce68ac10d6bdd70a4920bcc5-arm64

Afterwards, run the upgrade commands from the latest release notes.

* main:
  web: fix esbuild issue with style sheets (#8856)
  tenants: really ensure default tenant cannot be deleted (#8875)
  core: bump github.com/go-openapi/runtime from 0.27.2 to 0.28.0 (#8867)
  core: bump pytest from 8.0.2 to 8.1.1 (#8868)
  core: bump github.com/go-openapi/strfmt from 0.22.2 to 0.23.0 (#8869)
  core: bump bandit from 1.7.7 to 1.7.8 (#8870)
  core: bump packaging from 23.2 to 24.0 (#8871)
  core: bump ruff from 0.3.1 to 0.3.2 (#8873)
  web: bump the wdio group in /tests/wdio with 3 updates (#8865)
  core: bump requests-oauthlib from 1.3.1 to 1.4.0 (#8866)
  core: bump uvicorn from 0.27.1 to 0.28.0 (#8872)
  core: bump django-filter from 23.5 to 24.1 (#8874)
@kensternberg-authentik kensternberg-authentik merged commit 2ba66f4 into main Mar 11, 2024
60 checks passed
@kensternberg-authentik kensternberg-authentik deleted the web/upgrade-to-lit-3 branch March 11, 2024 17:47
kensternberg-authentik added a commit that referenced this pull request Mar 12, 2024
* main:
  web: upgrade to lit 3 (#8781)
kensternberg-authentik added a commit that referenced this pull request Mar 12, 2024
…ize-style-declaration

* main: (50 commits)
  Update _envoy_istio.md (#8888)
  website/docs: new landing page for Providers (#8879)
  web: bump the sentry group in /web with 1 update (#8881)
  web: bump chromedriver from 122.0.4 to 122.0.5 in /tests/wdio (#8884)
  web: bump the eslint group in /tests/wdio with 2 updates (#8883)
  web: bump the eslint group in /web with 2 updates (#8885)
  website: bump @types/react from 18.2.64 to 18.2.65 in /website (#8886)
  web: upgrade to lit 3 (#8781)
  web: fix esbuild issue with style sheets (#8856)
  tenants: really ensure default tenant cannot be deleted (#8875)
  core: bump github.com/go-openapi/runtime from 0.27.2 to 0.28.0 (#8867)
  core: bump pytest from 8.0.2 to 8.1.1 (#8868)
  core: bump github.com/go-openapi/strfmt from 0.22.2 to 0.23.0 (#8869)
  core: bump bandit from 1.7.7 to 1.7.8 (#8870)
  core: bump packaging from 23.2 to 24.0 (#8871)
  core: bump ruff from 0.3.1 to 0.3.2 (#8873)
  web: bump the wdio group in /tests/wdio with 3 updates (#8865)
  core: bump requests-oauthlib from 1.3.1 to 1.4.0 (#8866)
  core: bump uvicorn from 0.27.1 to 0.28.0 (#8872)
  core: bump django-filter from 23.5 to 24.1 (#8874)
  ...
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.

2 participants