-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Backoffice Performance: Inline entry point modules to reduce JS chunk count #21380
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
Merged
nielslyngsoe
merged 6 commits into
main
from
v17/improvement/inline-entry-point-modules
Jan 16, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f075b53
change to static import
madsrasmussen 0fbe3b7
add support for passing modules to manifest js property
madsrasmussen 8b91a46
Replaces dynamic imports of entry-point.js with static imports across…
madsrasmussen b912b7a
Support statically imported modules in loader functions
madsrasmussen 47b63bc
Add tests for loadManifest* functions in extension-api
madsrasmussen cca7f0d
Merge branch 'main' into v17/improvement/inline-entry-point-modules
nielslyngsoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...Umbraco.Web.UI.Client/src/libs/extension-api/functions/load-manifest-api.function.test.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import type { UmbApi } from '../models/api.interface.js'; | ||
| import { loadManifestApi } from './load-manifest-api.function.js'; | ||
| import { expect } from '@open-wc/testing'; | ||
|
|
||
| class UmbTestApiTrue implements UmbApi { | ||
| isValidClassInstance() { | ||
| return true; | ||
| } | ||
| destroy() {} | ||
| } | ||
|
|
||
| class UmbTestApiFalse implements UmbApi { | ||
| isValidClassInstance() { | ||
| return false; | ||
| } | ||
| destroy() {} | ||
| } | ||
|
|
||
| const jsModuleWithDefaultExport = { | ||
| default: UmbTestApiTrue, | ||
| }; | ||
|
|
||
| const jsModuleWithApiExport = { | ||
| api: UmbTestApiTrue, | ||
| }; | ||
|
|
||
| const jsModuleWithDefaultAndApiExport = { | ||
| default: UmbTestApiFalse, | ||
| api: UmbTestApiTrue, | ||
| }; | ||
|
|
||
| describe('loadManifestApi', () => { | ||
| describe('class constructor', () => { | ||
| it('returns the class constructor when passed directly', async () => { | ||
| const result = await loadManifestApi(UmbTestApiTrue); | ||
| expect(result).to.equal(UmbTestApiTrue); | ||
| }); | ||
| }); | ||
|
|
||
| describe('dynamic import (function)', () => { | ||
| it('returns the api class from default export', async () => { | ||
| const result = await loadManifestApi(() => Promise.resolve(jsModuleWithDefaultExport)); | ||
| expect(result).to.equal(UmbTestApiTrue); | ||
| }); | ||
|
|
||
| it('returns the api class from api export', async () => { | ||
| const result = await loadManifestApi(() => Promise.resolve(jsModuleWithApiExport)); | ||
| expect(result).to.equal(UmbTestApiTrue); | ||
| }); | ||
|
|
||
| it('prioritizes api export over default export', async () => { | ||
| const result = await loadManifestApi(() => Promise.resolve(jsModuleWithDefaultAndApiExport)); | ||
| expect(result).to.equal(UmbTestApiTrue); | ||
| }); | ||
|
|
||
| it('returns undefined when loader returns null', async () => { | ||
| const result = await loadManifestApi(() => Promise.resolve(null as any)); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
|
|
||
| it('returns undefined when loader returns object without valid exports', async () => { | ||
| const result = await loadManifestApi(() => Promise.resolve({ other: 'value' } as any)); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
|
|
||
| it('returns undefined when export is not a function', async () => { | ||
| const result = await loadManifestApi(() => Promise.resolve({ default: 'not-a-function' } as any)); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
| }); | ||
|
|
||
| describe('static import (object)', () => { | ||
| it('returns the api class from default export', async () => { | ||
| const result = await loadManifestApi(jsModuleWithDefaultExport); | ||
| expect(result).to.equal(UmbTestApiTrue); | ||
| }); | ||
|
|
||
| it('returns the api class from api export', async () => { | ||
| const result = await loadManifestApi(jsModuleWithApiExport); | ||
| expect(result).to.equal(UmbTestApiTrue); | ||
| }); | ||
|
|
||
| it('prioritizes api export over default export', async () => { | ||
| const result = await loadManifestApi(jsModuleWithDefaultAndApiExport); | ||
| expect(result).to.equal(UmbTestApiTrue); | ||
| }); | ||
|
|
||
| it('returns undefined when object has no valid exports', async () => { | ||
| const result = await loadManifestApi({ other: 'value' } as any); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
|
|
||
| it('returns undefined when export is not a function', async () => { | ||
| const result = await loadManifestApi({ default: 'not-a-function' } as any); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
| }); | ||
|
|
||
| describe('edge cases', () => { | ||
| it('returns undefined when passed null', async () => { | ||
| const result = await loadManifestApi(null as any); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
|
|
||
| it('returns undefined when passed undefined', async () => { | ||
| const result = await loadManifestApi(undefined as any); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
111 changes: 111 additions & 0 deletions
111
...aco.Web.UI.Client/src/libs/extension-api/functions/load-manifest-element.function.test.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { loadManifestElement } from './load-manifest-element.function.js'; | ||
| import { expect } from '@open-wc/testing'; | ||
| import { customElement } from '@umbraco-cms/backoffice/external/lit'; | ||
| import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; | ||
|
|
||
| @customElement('umb-test-element-true') | ||
| class UmbTestElementTrue extends UmbLitElement { | ||
| isValidClassInstance() { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| @customElement('umb-test-element-false') | ||
| class UmbTestElementFalse extends UmbLitElement { | ||
| isValidClassInstance() { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| const jsModuleWithDefaultExport = { | ||
| default: UmbTestElementTrue, | ||
| }; | ||
|
|
||
| const jsModuleWithElementExport = { | ||
| element: UmbTestElementTrue, | ||
| }; | ||
|
|
||
| const jsModuleWithDefaultAndElementExport = { | ||
| default: UmbTestElementFalse, | ||
| element: UmbTestElementTrue, | ||
| }; | ||
|
|
||
| describe('loadManifestElement', () => { | ||
| describe('class constructor', () => { | ||
| it('returns the class constructor when passed directly', async () => { | ||
| const result = await loadManifestElement(UmbTestElementTrue); | ||
| expect(result).to.equal(UmbTestElementTrue); | ||
| }); | ||
| }); | ||
|
|
||
| describe('dynamic import (function)', () => { | ||
| it('returns the element class from default export', async () => { | ||
| const result = await loadManifestElement(() => Promise.resolve(jsModuleWithDefaultExport)); | ||
| expect(result).to.equal(UmbTestElementTrue); | ||
| }); | ||
|
|
||
| it('returns the element class from element export', async () => { | ||
| const result = await loadManifestElement(() => Promise.resolve(jsModuleWithElementExport)); | ||
| expect(result).to.equal(UmbTestElementTrue); | ||
| }); | ||
|
|
||
| it('prioritizes element export over default export', async () => { | ||
| const result = await loadManifestElement(() => Promise.resolve(jsModuleWithDefaultAndElementExport)); | ||
| expect(result).to.equal(UmbTestElementTrue); | ||
| }); | ||
|
|
||
| it('returns undefined when loader returns null', async () => { | ||
| const result = await loadManifestElement(() => Promise.resolve(null as any)); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
|
|
||
| it('returns undefined when loader returns object without valid exports', async () => { | ||
| const result = await loadManifestElement(() => Promise.resolve({ other: 'value' } as any)); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
|
|
||
| it('returns undefined when export is not a function', async () => { | ||
| const result = await loadManifestElement(() => Promise.resolve({ default: 'not-a-function' } as any)); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
| }); | ||
|
|
||
| describe('static import (object)', () => { | ||
| it('returns the element class from default export', async () => { | ||
| const result = await loadManifestElement(jsModuleWithDefaultExport); | ||
| expect(result).to.equal(UmbTestElementTrue); | ||
| }); | ||
|
|
||
| it('returns the element class from element export', async () => { | ||
| const result = await loadManifestElement(jsModuleWithElementExport); | ||
| expect(result).to.equal(UmbTestElementTrue); | ||
| }); | ||
|
|
||
| it('prioritizes element export over default export', async () => { | ||
| const result = await loadManifestElement(jsModuleWithDefaultAndElementExport); | ||
| expect(result).to.equal(UmbTestElementTrue); | ||
| }); | ||
|
|
||
| it('returns undefined when object has no valid exports', async () => { | ||
| const result = await loadManifestElement({ other: 'value' } as any); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
|
|
||
| it('returns undefined when export is not a function', async () => { | ||
| const result = await loadManifestElement({ default: 'not-a-function' } as any); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
| }); | ||
|
|
||
| describe('edge cases', () => { | ||
| it('returns undefined when passed null', async () => { | ||
| const result = await loadManifestElement(null as any); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
|
|
||
| it('returns undefined when passed undefined', async () => { | ||
| const result = await loadManifestElement(undefined as any); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
63 changes: 63 additions & 0 deletions
63
...co.Web.UI.Client/src/libs/extension-api/functions/load-manifest-plain-js.function.test.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { loadManifestPlainJs } from './load-manifest-plain-js.function.js'; | ||
| import { expect } from '@open-wc/testing'; | ||
|
|
||
| interface TestModule { | ||
| value: string; | ||
| getValue(): string; | ||
| } | ||
|
|
||
| const testModuleObject: TestModule = { | ||
| value: 'test-value', | ||
| getValue() { | ||
| return this.value; | ||
| }, | ||
| }; | ||
|
|
||
| const jsModuleWithTestExport = { | ||
| value: 'dynamic-import-value', | ||
| getValue() { | ||
| return this.value; | ||
| }, | ||
| }; | ||
|
|
||
| describe('loadManifestPlainJs', () => { | ||
| describe('dynamic import (function)', () => { | ||
| it('returns the module when loader returns an object', async () => { | ||
| const result = await loadManifestPlainJs<TestModule>(() => Promise.resolve(jsModuleWithTestExport)); | ||
| expect(result).to.not.be.undefined; | ||
| expect(result?.value).to.equal('dynamic-import-value'); | ||
| expect(result?.getValue()).to.equal('dynamic-import-value'); | ||
| }); | ||
|
|
||
| it('returns undefined when loader returns null', async () => { | ||
| const result = await loadManifestPlainJs<TestModule>(() => Promise.resolve(null as unknown as TestModule)); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
|
|
||
| it('returns undefined when loader returns a primitive', async () => { | ||
| const result = await loadManifestPlainJs<TestModule>(() => Promise.resolve('string' as unknown as TestModule)); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
| }); | ||
|
|
||
| describe('static import (object)', () => { | ||
| it('returns the module object directly when passed an object', async () => { | ||
| const result = await loadManifestPlainJs<TestModule>(testModuleObject); | ||
| expect(result).to.not.be.undefined; | ||
| expect(result?.value).to.equal('test-value'); | ||
| expect(result?.getValue()).to.equal('test-value'); | ||
| }); | ||
|
|
||
| it('returns undefined when passed null', async () => { | ||
| const result = await loadManifestPlainJs<TestModule>(null as unknown as TestModule); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
| }); | ||
|
|
||
| describe('edge cases', () => { | ||
| it('returns undefined when passed undefined', async () => { | ||
| const result = await loadManifestPlainJs<TestModule>(undefined as unknown as TestModule); | ||
| expect(result).to.be.undefined; | ||
| }); | ||
| }); | ||
| }); |
20 changes: 12 additions & 8 deletions
20
...Umbraco.Web.UI.Client/src/libs/extension-api/functions/load-manifest-plain-js.function.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,27 @@ | ||
| import type { JsLoaderProperty } from '../types/utils.js'; | ||
| import type { JsLoaderPromise } from '../types/utils.js'; | ||
|
|
||
| /** | ||
| * | ||
| * @param property | ||
| */ | ||
| export async function loadManifestPlainJs<JsType>(property: JsLoaderProperty<JsType>): Promise<JsType | undefined> { | ||
| const propType = typeof property; | ||
| if (propType === 'function') { | ||
| // Promise function | ||
| const result = await (property as Exclude<typeof property, string>)(); | ||
| export async function loadManifestPlainJs<JsType>( | ||
| property: string | JsLoaderPromise<JsType> | JsType, | ||
| ): Promise<JsType | undefined> { | ||
| if (typeof property === 'function') { | ||
| // Promise function (dynamic import) | ||
| const result = await (property as JsLoaderPromise<JsType>)(); | ||
| if (typeof result === 'object' && result != null) { | ||
| return result; | ||
| } | ||
| } else if (propType === 'string') { | ||
| } else if (typeof property === 'string') { | ||
| // Import string | ||
| const result = await (import(/* @vite-ignore */ property as string) as unknown as JsType); | ||
| const result = await (import(/* @vite-ignore */ property) as unknown as JsType); | ||
| if (typeof result === 'object' && result != null) { | ||
| return result; | ||
| } | ||
| } else if (typeof property === 'object' && property != null) { | ||
| // Already resolved module object (statically imported) | ||
| return property; | ||
|
Check warning on line 24 in src/Umbraco.Web.UI.Client/src/libs/extension-api/functions/load-manifest-plain-js.function.ts
|
||
| } | ||
| return undefined; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.