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

feat: migrate editor-ui to Vite.js and various DX improvements (N8N-2277) #4061

Merged
merged 61 commits into from
Sep 23, 2022

Conversation

alexgrozav
Copy link
Member

No description provided.

@n8n-assistant n8n-assistant bot added n8n team Authored by the n8n team ui Enhancement in /editor-ui or /design-system labels Sep 8, 2022
@alexgrozav alexgrozav changed the title N8N-2277 Editor UI Vite.js migration feat: Editor UI Vite.js migration (N8N-2277) Sep 12, 2022
Copy link
Contributor

@mutdmour mutdmour left a comment

Choose a reason for hiding this comment

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

Looks good overall. Cannot approve because of outstanding issues that need to be resolved

import { WorkflowActivationError } from './WorkflowActivationError';
import { WorkflowOperationError } from './WorkflowErrors';
import { NodeApiError, NodeOperationError } from './NodeErrors';
import type { Workflow } from './Workflow';
Copy link
Contributor

Choose a reason for hiding this comment

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

why is type needed now?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a typescript feature that allows you to import declarations only, comes in handy when you need to remove circular references and imports.

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html

Copy link
Contributor

Choose a reason for hiding this comment

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

They should all be type imports.

@@ -1,7 +1,5 @@
@import "./n8n-theme-variables";

@import "~n8n-design-system/theme/dist/index.css";
Copy link
Contributor

Choose a reason for hiding this comment

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

how are we importing this now?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're importing it directly in design-system/src/main.js. Doing so allows the build system to split into chunks and write font/asset paths properly.

https://github.com/n8n-io/n8n/pull/4061/files/0ab42166505e390ec27336f4c3e934eb5cac7c45#diff-2396dce48aeead825ea11d2267d6213773ebcb0887535809073d8ea228daed3b

@ivov
Copy link
Contributor

ivov commented Sep 23, 2022

Found this error on 5678 when switching locale:

Uncaught (in promise) Error: Unknown variable dynamic import: ./locales/de.json
    __variableDynamicImportRuntime0__ http://localhost:5678/assets/index.754241ce.js:16669
    __variableDynamicImportRuntime0__ http://localhost:5678/assets/index.754241ce.js:16669
    loadLanguage http://localhost:5678/assets/index.754241ce.js:16669
    defaultLocale http://localhost:5678/assets/index.754241ce.js:16669
    invokeWithErrorHandling http://localhost:5678/assets/index.754241ce.js:5
    run http://localhost:5678/assets/index.754241ce.js:5
    flushSchedulerQueue http://localhost:5678/assets/index.754241ce.js:5
    nextTick http://localhost:5678/assets/index.754241ce.js:5
    flushCallbacks http://localhost:5678/assets/index.754241ce.js:5
    promise callback*timerFunc http://localhost:5678/assets/index.754241ce.js:5
    nextTick http://localhost:5678/assets/index.754241ce.js:5
    queueWatcher http://localhost:5678/assets/index.754241ce.js:5
    update http://localhost:5678/assets/index.754241ce.js:5
    notify http://localhost:5678/assets/index.754241ce.js:5
    set http://localhost:5678/assets/index.754241ce.js:5
    set$1 http://localhost:5678/assets/index.754241ce.js:5
    setDefaultLocale http://localhost:5678/assets/index.754241ce.js:16874
    registerMutation http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    _withCommit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    getSettings http://localhost:5678/assets/index.754241ce.js:16874
    registerAction http://localhost:5678/assets/index.754241ce.js:609
    dispatch http://localhost:5678/assets/index.754241ce.js:609
    dispatch http://localhost:5678/assets/index.754241ce.js:609
    initSettings http://localhost:5678/assets/index.754241ce.js:16669
    initialize http://localhost:5678/assets/index.754241ce.js:16669
    mounted http://localhost:5678/assets/index.754241ce.js:16669
    invokeWithErrorHandling http://localhost:5678/assets/index.754241ce.js:5
    callHook http://localhost:5678/assets/index.754241ce.js:5
    insert http://localhost:5678/assets/index.754241ce.js:5
    z http://localhost:5678/assets/index.754241ce.js:5
    createPatchFunction http://localhost:5678/assets/index.754241ce.js:5
    _update http://localhost:5678/assets/index.754241ce.js:5
    u http://localhost:5678/assets/index.754241ce.js:5
    get http://localhost:5678/assets/index.754241ce.js:5
    Watcher http://localhost:5678/assets/index.754241ce.js:5
    mountComponent http://localhost:5678/assets/index.754241ce.js:5
    $mount http://localhost:5678/assets/index.754241ce.js:5
    <anonymous> http://localhost:5678/assets/index.754241ce.js:16874

To reproduce, create packages/editor-ui/src/plugins/i18n/locales/de.json, edit all values to make it visually clear it is a different locale, export N8N_DEFAULT_LOCALE=de on 5678 and start. Editing the de.json triggers hot reload on 8080, but its translated strings are not used. Docs link.

@alexgrozav
Copy link
Member Author

One lingering concern. On refreshing or returning to the canvas, master is perceptively faster than the Vite branch on 5678 and 8080, although metrics like DOMContentLoaded are much better.

@ivov Only the first few loads will be slower until Vite creates the dependencies graph and caches it. Subsequent starts are much faster than webpack. At least that's how it is for me.

@alexgrozav
Copy link
Member Author

Found this error on 5678 when switching locale:

Uncaught (in promise) Error: Unknown variable dynamic import: ./locales/de.json
    __variableDynamicImportRuntime0__ http://localhost:5678/assets/index.754241ce.js:16669
    __variableDynamicImportRuntime0__ http://localhost:5678/assets/index.754241ce.js:16669
    loadLanguage http://localhost:5678/assets/index.754241ce.js:16669
    defaultLocale http://localhost:5678/assets/index.754241ce.js:16669
    invokeWithErrorHandling http://localhost:5678/assets/index.754241ce.js:5
    run http://localhost:5678/assets/index.754241ce.js:5
    flushSchedulerQueue http://localhost:5678/assets/index.754241ce.js:5
    nextTick http://localhost:5678/assets/index.754241ce.js:5
    flushCallbacks http://localhost:5678/assets/index.754241ce.js:5
    promise callback*timerFunc http://localhost:5678/assets/index.754241ce.js:5
    nextTick http://localhost:5678/assets/index.754241ce.js:5
    queueWatcher http://localhost:5678/assets/index.754241ce.js:5
    update http://localhost:5678/assets/index.754241ce.js:5
    notify http://localhost:5678/assets/index.754241ce.js:5
    set http://localhost:5678/assets/index.754241ce.js:5
    set$1 http://localhost:5678/assets/index.754241ce.js:5
    setDefaultLocale http://localhost:5678/assets/index.754241ce.js:16874
    registerMutation http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    _withCommit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    getSettings http://localhost:5678/assets/index.754241ce.js:16874
    registerAction http://localhost:5678/assets/index.754241ce.js:609
    dispatch http://localhost:5678/assets/index.754241ce.js:609
    dispatch http://localhost:5678/assets/index.754241ce.js:609
    initSettings http://localhost:5678/assets/index.754241ce.js:16669
    initialize http://localhost:5678/assets/index.754241ce.js:16669
    mounted http://localhost:5678/assets/index.754241ce.js:16669
    invokeWithErrorHandling http://localhost:5678/assets/index.754241ce.js:5
    callHook http://localhost:5678/assets/index.754241ce.js:5
    insert http://localhost:5678/assets/index.754241ce.js:5
    z http://localhost:5678/assets/index.754241ce.js:5
    createPatchFunction http://localhost:5678/assets/index.754241ce.js:5
    _update http://localhost:5678/assets/index.754241ce.js:5
    u http://localhost:5678/assets/index.754241ce.js:5
    get http://localhost:5678/assets/index.754241ce.js:5
    Watcher http://localhost:5678/assets/index.754241ce.js:5
    mountComponent http://localhost:5678/assets/index.754241ce.js:5
    $mount http://localhost:5678/assets/index.754241ce.js:5
    <anonymous> http://localhost:5678/assets/index.754241ce.js:16874

To reproduce, create packages/editor-ui/src/plugins/i18n/locales/de.json, edit all values to make it visually clear it is a different locale, export N8N_DEFAULT_LOCALE=de on 5678 and start. Editing the de.json triggers hot reload on 8080, but its translated strings are not used. Docs link.

Good catch, working on fixing it!

@ivov
Copy link
Contributor

ivov commented Sep 23, 2022

Whitespace and ampersands missing on node panel category headers:

image

@alexgrozav
Copy link
Member Author

Found this error on 5678 when switching locale:

Uncaught (in promise) Error: Unknown variable dynamic import: ./locales/de.json
    __variableDynamicImportRuntime0__ http://localhost:5678/assets/index.754241ce.js:16669
    __variableDynamicImportRuntime0__ http://localhost:5678/assets/index.754241ce.js:16669
    loadLanguage http://localhost:5678/assets/index.754241ce.js:16669
    defaultLocale http://localhost:5678/assets/index.754241ce.js:16669
    invokeWithErrorHandling http://localhost:5678/assets/index.754241ce.js:5
    run http://localhost:5678/assets/index.754241ce.js:5
    flushSchedulerQueue http://localhost:5678/assets/index.754241ce.js:5
    nextTick http://localhost:5678/assets/index.754241ce.js:5
    flushCallbacks http://localhost:5678/assets/index.754241ce.js:5
    promise callback*timerFunc http://localhost:5678/assets/index.754241ce.js:5
    nextTick http://localhost:5678/assets/index.754241ce.js:5
    queueWatcher http://localhost:5678/assets/index.754241ce.js:5
    update http://localhost:5678/assets/index.754241ce.js:5
    notify http://localhost:5678/assets/index.754241ce.js:5
    set http://localhost:5678/assets/index.754241ce.js:5
    set$1 http://localhost:5678/assets/index.754241ce.js:5
    setDefaultLocale http://localhost:5678/assets/index.754241ce.js:16874
    registerMutation http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    _withCommit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    getSettings http://localhost:5678/assets/index.754241ce.js:16874
    registerAction http://localhost:5678/assets/index.754241ce.js:609
    dispatch http://localhost:5678/assets/index.754241ce.js:609
    dispatch http://localhost:5678/assets/index.754241ce.js:609
    initSettings http://localhost:5678/assets/index.754241ce.js:16669
    initialize http://localhost:5678/assets/index.754241ce.js:16669
    mounted http://localhost:5678/assets/index.754241ce.js:16669
    invokeWithErrorHandling http://localhost:5678/assets/index.754241ce.js:5
    callHook http://localhost:5678/assets/index.754241ce.js:5
    insert http://localhost:5678/assets/index.754241ce.js:5
    z http://localhost:5678/assets/index.754241ce.js:5
    createPatchFunction http://localhost:5678/assets/index.754241ce.js:5
    _update http://localhost:5678/assets/index.754241ce.js:5
    u http://localhost:5678/assets/index.754241ce.js:5
    get http://localhost:5678/assets/index.754241ce.js:5
    Watcher http://localhost:5678/assets/index.754241ce.js:5
    mountComponent http://localhost:5678/assets/index.754241ce.js:5
    $mount http://localhost:5678/assets/index.754241ce.js:5
    <anonymous> http://localhost:5678/assets/index.754241ce.js:16874

To reproduce, create packages/editor-ui/src/plugins/i18n/locales/de.json, edit all values to make it visually clear it is a different locale, export N8N_DEFAULT_LOCALE=de on 5678 and start. Editing the de.json triggers hot reload on 8080, but its translated strings are not used. Docs link.

Good catch, working on fixing it!

Found this error on 5678 when switching locale:

Uncaught (in promise) Error: Unknown variable dynamic import: ./locales/de.json
    __variableDynamicImportRuntime0__ http://localhost:5678/assets/index.754241ce.js:16669
    __variableDynamicImportRuntime0__ http://localhost:5678/assets/index.754241ce.js:16669
    loadLanguage http://localhost:5678/assets/index.754241ce.js:16669
    defaultLocale http://localhost:5678/assets/index.754241ce.js:16669
    invokeWithErrorHandling http://localhost:5678/assets/index.754241ce.js:5
    run http://localhost:5678/assets/index.754241ce.js:5
    flushSchedulerQueue http://localhost:5678/assets/index.754241ce.js:5
    nextTick http://localhost:5678/assets/index.754241ce.js:5
    flushCallbacks http://localhost:5678/assets/index.754241ce.js:5
    promise callback*timerFunc http://localhost:5678/assets/index.754241ce.js:5
    nextTick http://localhost:5678/assets/index.754241ce.js:5
    queueWatcher http://localhost:5678/assets/index.754241ce.js:5
    update http://localhost:5678/assets/index.754241ce.js:5
    notify http://localhost:5678/assets/index.754241ce.js:5
    set http://localhost:5678/assets/index.754241ce.js:5
    set$1 http://localhost:5678/assets/index.754241ce.js:5
    setDefaultLocale http://localhost:5678/assets/index.754241ce.js:16874
    registerMutation http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    _withCommit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    commit http://localhost:5678/assets/index.754241ce.js:609
    getSettings http://localhost:5678/assets/index.754241ce.js:16874
    registerAction http://localhost:5678/assets/index.754241ce.js:609
    dispatch http://localhost:5678/assets/index.754241ce.js:609
    dispatch http://localhost:5678/assets/index.754241ce.js:609
    initSettings http://localhost:5678/assets/index.754241ce.js:16669
    initialize http://localhost:5678/assets/index.754241ce.js:16669
    mounted http://localhost:5678/assets/index.754241ce.js:16669
    invokeWithErrorHandling http://localhost:5678/assets/index.754241ce.js:5
    callHook http://localhost:5678/assets/index.754241ce.js:5
    insert http://localhost:5678/assets/index.754241ce.js:5
    z http://localhost:5678/assets/index.754241ce.js:5
    createPatchFunction http://localhost:5678/assets/index.754241ce.js:5
    _update http://localhost:5678/assets/index.754241ce.js:5
    u http://localhost:5678/assets/index.754241ce.js:5
    get http://localhost:5678/assets/index.754241ce.js:5
    Watcher http://localhost:5678/assets/index.754241ce.js:5
    mountComponent http://localhost:5678/assets/index.754241ce.js:5
    $mount http://localhost:5678/assets/index.754241ce.js:5
    <anonymous> http://localhost:5678/assets/index.754241ce.js:16874

To reproduce, create packages/editor-ui/src/plugins/i18n/locales/de.json, edit all values to make it visually clear it is a different locale, export N8N_DEFAULT_LOCALE=de on 5678 and start. Editing the de.json triggers hot reload on 8080, but its translated strings are not used. Docs link.

Good catch, working on fixing it!

Looks like we both contributed a bit to this 😅. Fixed!

@alexgrozav
Copy link
Member Author

Whitespace and ampersands missing on node panel category headers:

image

This is translations related. Got fixed together with the previous fix.

@alexgrozav alexgrozav changed the title feat: Editor UI Vite.js migration (N8N-2277) feat: migrate editor-ui to Vite.js and various DX improvements (N8N-2277) Sep 23, 2022
readIndexFile = readIndexFile.replace(/\/favicon.ico/g, `${n8nPath}favicon.ico`);

const cssPath = pathJoin(pathDirname(editorUiPath), 'dist', '**/*.css');
Copy link
Member

Choose a reason for hiding this comment

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

This change means that we'll be keeping a copy of all JS and CSS files in the memory, and increasing the overall memory usage of every instance. Also, this makes gzipping these resources more difficult, which is not really an issue as we are currently not compressing any of our assets (from what I can tell).
However. this isn't a blocker. I can take care of optimizing these and setting up compression in another PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks a lot, Adi. I've crated a task for it: https://linear.app/n8n/issue/N8N-4739

@netroy
Copy link
Member

netroy commented Sep 23, 2022

One lingering concern. On refreshing or returning to the canvas, master is perceptively faster than the Vite branch on 5678 and 8080, although metrics like DOMContentLoaded are much better.

@ivov Only the first few loads will be slower until Vite creates the dependencies graph and caches it. Subsequent starts are much faster than webpack. At least that's how it is for me.

I'm seeing this issue on my staging instance. every reload takes significantly longer than it used to. even though none of the http requests seem slow.

@alexgrozav
Copy link
Member Author

Interesting. I see now. I thought @ivov was referring to initial page load. I'll try to do something about this.

@@ -58,8 +58,7 @@ const module: Module<INodeTypesState, IRootState> = {
},
mutations: {
setNodeTypes(state, newNodeTypes: INodeTypeDescription[]) {
// tslint:disable-next-line:no-any
const nodeTypes = newNodeTypes.reduce((acc: any, newNodeType) => {
const nodeTypes = newNodeTypes.reduce((acc: Record<string, Record<string, INodeTypeDescription>>, newNodeType) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The type for the accumulator is provided as a generic to reduce

Copy link
Member Author

Choose a reason for hiding this comment

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

Today I learned 😃

Copy link
Contributor

@mutdmour mutdmour left a comment

Choose a reason for hiding this comment

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

🍻

@alexgrozav alexgrozav merged commit 27e2ce0 into master Sep 23, 2022
@alexgrozav alexgrozav deleted the n8n-2277-editor-ui-vite-migration branch September 23, 2022 14:14
@n8n-assistant n8n-assistant bot added the Upcoming Release Will be part of the upcoming release label Sep 23, 2022
@janober
Copy link
Member

janober commented Sep 30, 2022

Got released with [email protected]

@janober janober removed the Upcoming Release Will be part of the upcoming release label Sep 30, 2022
valya pushed a commit to valya/n8n that referenced this pull request Nov 8, 2022
…277) (n8n-io#4061)

* feat: Added vite.js dependencies.

* chore: Removed tests folder to follow same structure as design-system

* chore: Removed unused testing config.

* chore: Created vite.js index.html

* refactor: Updated scss structure and imports.

* refactor: Updated workflow building.

* fix: Cleared up all workflow dependency cycles. Added proper package.json imports config.

* feat: Got a working build using Vite. Need to fix issues next.

* fix: Progress! Getting process.env error.

* fix: Changed process.env to import.meta.env.

* fix: Fixed circular imports that used require(). Fixed monaco editor.

* chore: Removed commented code.

* chore: Cleaned up package.json

* feat: Made necessary changes to replace base path in css files.

* feat: Serve CSS files for `editor-ui` Vite migration (n8n-io#4069)

:zap: Serve CSS files for Vite migration

* chore: Fixed package-lock.json.

* fix: Fixed build after centralized tsconfig update.

* fix: Removed lodash-es replacement.

* fix: Commented out vitest test command.

* style: Fixed linting issues.

* fix: Added lodash-es hotfix back.

* chore: Updated package-lock.json

* refactor: Renamed all n8n scss variables to no longer be defined as private.

* feat(editor): add application-wide el-button replacement.

* fix(editor): Fix import in page alert after merge.

* chore(editor): update package-lock.json.

* fix: Case sensitive lodash-es replacement for vue-agile.

* fix: add alias for lodash-es camelcase import.

* fix: add patch-package support for fixing quill

* feat: add patch-package on postinstall

* fix: update quill patch path.

* refactor: rename quill patch

* fix: update quill version.

* fix: update quill patch

* fix: fix linting rules after installing eslint in design-system

* fix: update date picker button to have primary color

* test: update callout component snapshots

* fix(editor): fix linting issues in editor after enabling eslint

* fix(cli): add /assets/* to auth ignore endpoints in server

* chore: update package-lock.json

* chore: update package-lock.json

* fix(editor): fix linting issues

* feat: add vite-legacy support

* fix: update workflow package interface imports to type imports.

* chore: update package-lock.json

* fix(editor) fix importing translations other than english

* fix(editor): remove test command until vitest is added

* fix: increase memory allocation for vite build

* fix: add patch-package patches to n8n-custom docker build

* fix: add performance and load time improvements

* fix: add proper typing to setNodeType

* chore: update package-lock.json

* style: use generic type for reduce in setNodeType

Co-authored-by: Iván Ovejero <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team ui Enhancement in /editor-ui or /design-system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants