Compare commits

...
Author SHA1 Message Date
Timo K. a135a7404e Merge branch 'main' into toger5/embedded-without-crypto 2026-11-27 13:25:14 +01:00
Timo 0118be7ee7 Merge pull request #4515 from element-hq/toger5/sdk-build-modes
[sdk] Add development builds of the matrixrtc-sdk and fix the component's
2026-11-27 13:13:42 +01:00
Timo 788f43f578 Merge pull request #4480 from element-hq/toger5/peer-dependency
Solve EW <-> EC Peer dependency
2026-11-27 13:12:09 +01:00
renovate[bot] c0370c254c Update ghcr.io/element-hq/element-web:develop Docker digest to 58b673f (#4513)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-11-27 02:08:46 +00:00
Timo K.andClaude Opus 5.5 4f6a919aa6 Add production and development builds of the matrixrtc-sdk
build:sdk had a single, always minified build. build:sdk:production and
build:sdk:development now match the component's pair:
vite-sdk.config.ts already minified only in production mode, so only the
scripts were missing. `--mode` goes on build:sdk:js, the Vite step,
since pnpm would append it after the types step.

Source maps stay on in both modes, as for the component: they ship with
the package for the host to debug with. `prepare` keeps calling build:sdk,
so a git-dependency install is unchanged.

Closes #3714

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 18:05:34 +01:00
Timo K.andClaude Opus 5.5 13ce1c2648 Build the component in development mode for build:component:development
pnpm appends extra arguments to the end of a script, so the `--mode
development` that build:component:development passed to build:component:js
landed on check-component-bundle.mjs rather than on Vite, and the
"development" build came out minified like the production one.

The bundle check is now a script of its own, build:component:check, which
leaves build:component:js a single Vite call that `--mode` reaches. The
steps still run in the same order: Vite, the check, the types.

The development build is now unminified (element-call.js 3.64 MB against
2.34 MB) and passes the check, a little under its 4 MiB module budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 18:05:30 +01:00
Timo K. e15b3f9914 over the standalone client loader in both packages 2026-11-26 15:11:55 +01:00
Timo K. 4bb407afc0 remove crypto wasm from embedded target 2026-11-25 15:18:14 +01:00
10 changed files with 79 additions and 12 deletions
+2 -2
View File
@@ -19,10 +19,10 @@ services:
- ./backend/playwright_homeserver-othersite.yaml:/data/cfg/homeserver.yaml:Z
element-web:
# Pin to a SHA so that upstream cannot break our tests. Renovate handles regular updates.
image: ghcr.io/element-hq/element-web:develop@sha256:c850f5058acf2eeb9ed4b392f2f3e53b02240e7a74af8e5f7cc8424d12974c49
image: ghcr.io/element-hq/element-web:develop@sha256:58b673f867f78fe83c08f2b688b254e34625ebfcebdc5eff84bfdf407445e88e
element-web-1:
# Pin to a SHA so that upstream cannot break our tests. Renovate handles regular updates.
image: ghcr.io/element-hq/element-web:develop@sha256:c850f5058acf2eeb9ed4b392f2f3e53b02240e7a74af8e5f7cc8424d12974c49
image: ghcr.io/element-hq/element-web:develop@sha256:58b673f867f78fe83c08f2b688b254e34625ebfcebdc5eff84bfdf407445e88e
volumes:
# The other site opens the embedded package under test in place of the
# copy its image bundles (the first site opens the dev server's app.
+2 -1
View File
@@ -108,7 +108,8 @@ Code that builds in only one is a bug.
- `build:sdk` — `@element-hq/matrixrtc-sdk`, sources in `sdk/`, entry `sdk/index.ts`.
Packaged exactly like the component (own pnpm project, run pnpm from the repo
root, types from `sdk/tsconfig.build.json`, externals checked by
`pnpm lint:externals`).
`pnpm lint:externals`). Minified by default (`build:sdk:production`),
unminified with `build:sdk:development`; source maps in both.
- `build:widget-rtc-sdk` — a single bundle for widget pages that wraps the
`sdk/` package and the widget API, nothing of `src/`; entry
`widget-rtc-sdk/main.ts`. CI builds it as the `widget-rtc-sdk` package
+6 -3
View File
@@ -19,14 +19,17 @@
"build:sdk": "pnpm build:sdk:js && pnpm build:sdk:types",
"build:sdk:js": "pnpm build:full --config vite-sdk.config.js",
"build:sdk:types": "tsc -p sdk/tsconfig.build.json",
"build:sdk:production": "pnpm build:sdk",
"build:sdk:development": "pnpm build:sdk:js --mode development && pnpm build:sdk:types",
"build:widget-rtc-sdk": "pnpm build:full --config vite-widget-rtc-sdk.config.js",
"build:widget-rtc-sdk:production": "pnpm build:widget-rtc-sdk",
"build:widget-rtc-sdk:development": "pnpm build:widget-rtc-sdk --mode development",
"build:component": "pnpm build:component:js && pnpm build:component:types",
"build:component:js": "pnpm build:full --config vite-component.config.js && node scripts/check-component-bundle.mjs",
"build:component": "pnpm build:component:js && pnpm build:component:check && pnpm build:component:types",
"build:component:js": "pnpm build:full --config vite-component.config.js",
"build:component:check": "node scripts/check-component-bundle.mjs",
"build:component:types": "tsc -p component/tsconfig.build.json",
"build:component:production": "pnpm build:component",
"build:component:development": "pnpm build:component:js --mode development && pnpm build:component:types",
"build:component:development": "pnpm build:component:js --mode development && pnpm build:component:check && pnpm build:component:types",
"serve": "vite preview",
"format": "oxfmt",
"format:check": "oxfmt --check; rc=$?; [[ $rc -ne 0 ]] && printf '\\033[46;30m INFO \\033[0m To fix, run: pnpm format\\n' >&2; exit $rc",
+7 -2
View File
@@ -5,9 +5,10 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { test as setup } from "@playwright/test";
import { expect, test as setup } from "@playwright/test";
import { execFileSync } from "node:child_process";
import { mkdirSync } from "node:fs";
import { mkdirSync, readdirSync } from "node:fs";
import { join } from "node:path";
const EMBEDDED_DIST = "embedded/web/dist";
@@ -17,4 +18,8 @@ setup("build the embedded package", () => {
execFileSync("pnpm", ["build:embedded", "--outDir", EMBEDDED_DIST], {
stdio: "inherit",
});
// The host does the crypto, and nothing runs the standalone client
expect(readdirSync(join(EMBEDDED_DIST, "assets"))).not.toContainEqual(
expect.stringMatching(/rust-crypto|matrix_sdk_crypto|IndexedDBWorker/),
);
});
+1
View File
@@ -99,6 +99,7 @@ own only so that a host can install it as a git dependency (see
```sh
pnpm dev:sdk # the harness, https://localhost:3002
pnpm build:sdk # dist/matrixrtc-sdk.js and dist/types
pnpm build:sdk:development # the same, unminified
pnpm test:playwright playwright/sdk # needs `pnpm backend`
```
+37
View File
@@ -0,0 +1,37 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { afterEach, expect, test, vi } from "vitest";
const initSPA = vi.hoisted(() => vi.fn());
vi.mock("./utils/spa", () => ({ initSPA }));
afterEach(() => {
vi.unstubAllEnvs();
vi.resetModules();
initSPA.mockReset();
});
test("the app restores its own session", async () => {
vi.stubEnv("VITE_PACKAGE", "full");
const { loadStandaloneClient } = await import("./App");
const loadSession = vi.fn();
const clearSession = vi.fn();
initSPA.mockResolvedValue(null);
await expect(loadStandaloneClient!(loadSession, clearSession)).resolves.toBe(
null,
);
expect(initSPA).toHaveBeenCalledWith(loadSession, clearSession);
});
test("the embedded package has no session of its own", async () => {
vi.stubEnv("VITE_PACKAGE", "embedded");
const { loadStandaloneClient } = await import("./App");
expect(loadStandaloneClient).toBeUndefined();
});
+6 -2
View File
@@ -64,8 +64,12 @@ const SentryRoute = Sentry.withSentryReactRouterV7Routing(Route);
// - Imported on demand, as it was before, so that a widget, which gets its
// client from the host, never downloads it.
// - Module-level, so that the provider's effect sees one stable loader.
const loadStandaloneClient: ClientLoader = async (...args) =>
(await import("./utils/spa")).initSPA(...args);
// - None in the embedded package, which only runs as a widget: the constant
// condition lets its build drop the client setup and the store worker.
export const loadStandaloneClient: ClientLoader | undefined =
import.meta.env.VITE_PACKAGE === "embedded"
? undefined
: async (...args) => (await import("./utils/spa")).initSPA(...args);
interface SimpleProviderProps {
children: JSX.Element;
+2 -1
View File
@@ -7,7 +7,7 @@ Please see LICENSE in the repository root for full details.
import { defineConfig, mergeConfig } from "vite";
import fullConfig from "./vite.config.ts";
import fullConfig, { withoutMatrixCrypto } from "./vite.config.ts";
const base = "./";
@@ -18,6 +18,7 @@ export default defineConfig((env) =>
defineConfig({
base, // Use relative URLs to allow the app to be hosted under any path
publicDir: false, // Don't serve the public directory which only contains the favicon
plugins: [withoutMatrixCrypto({ withoutStoreWorker: true })],
}),
),
);
+3
View File
@@ -22,6 +22,9 @@ export default defineConfig(({ mode }) => {
// Into the package directory, so that `sdk/package.json` describes what
// sits next to it and the directory can be installed as a package
outDir: "sdk/dist",
// Minified for production (`build:sdk`, `build:sdk:production`), readable
// in development (`build:sdk:development`). Source maps in both, as for
// the component: they ship with the package for the host to debug with.
minify: mode === "production",
sourcemap: true,
lib: {
+13 -1
View File
@@ -201,9 +201,17 @@ export default ({
* encrypts and decrypts for it, so the Rust crypto chunk and its WASM (about
* 10 MB) would only be shipped, never loaded. The SDK imports it dynamically,
* from `initRustCrypto` and `preloadRustCrypto`; here those reject instead.
*
* With `withoutStoreWorker`, the worker behind the standalone client's sync
* store goes too, for a build that contains the standalone client's code but
* never runs it. The worker is a second copy of the SDK with the crypto, and
* the bundler emits it as soon as anything imports it.
*/
export function withoutMatrixCrypto(): Plugin {
export function withoutMatrixCrypto({
withoutStoreWorker = false,
}: { withoutStoreWorker?: boolean } = {}): Plugin {
const crypto = "\0without-matrix-crypto";
const worker = "\0without-matrix-store-worker";
const unavailable =
"new Error('This build uses the client of its host, which does the crypto')";
return {
@@ -215,6 +223,8 @@ export function withoutMatrixCrypto(): Plugin {
/(^|\/)rust-crypto\/index(\.js)?$/.test(source)
)
return crypto;
if (withoutStoreWorker && source.endsWith("/IndexedDBWorker?worker"))
return worker;
return null;
},
load(id): string | null {
@@ -223,6 +233,8 @@ export function withoutMatrixCrypto(): Plugin {
`export async function initRustCrypto() { throw ${unavailable}; }`,
`export async function preloadRustCrypto() { throw ${unavailable}; }`,
].join("\n");
if (id === worker)
return `export default class { constructor() { throw ${unavailable}; } }`;
return null;
},
};