diff --git a/src/editor/configuration.js b/src/editor/configuration.js
index 5661a4a26..b432880c8 100644
--- a/src/editor/configuration.js
+++ b/src/editor/configuration.js
@@ -10,7 +10,7 @@ export default class EditorConfiguration {
this.#editorElement = editorElement
this.#config = new Configuration(
Lexxy.presets.get("default"),
- Lexxy.presets.get(editorElement.preset),
+ this.#presetConfig,
this.#overrides
)
}
@@ -19,6 +19,18 @@ export default class EditorConfiguration {
return this.#config.get(path)
}
+ get #presetConfig() {
+ const preset = this.#editorElement.preset
+ const config = Lexxy.presets.get(preset)
+
+ if (config) {
+ return config
+ } else {
+ console.warn(`Unknown Lexxy preset "${preset}". Falling back to the default preset.`)
+ return {}
+ }
+ }
+
get #overrides() {
const overrides = {}
for (const option of this.#defaultOptions) {
diff --git a/test/browser/fixtures/unknown-preset.html b/test/browser/fixtures/unknown-preset.html
new file mode 100644
index 000000000..eacfd585d
--- /dev/null
+++ b/test/browser/fixtures/unknown-preset.html
@@ -0,0 +1,20 @@
+
+
+
+
+
+ Lexxy Unknown Preset
+
+
+
+
+
+
+
+
diff --git a/test/browser/tests/editor/unknown_preset.test.js b/test/browser/tests/editor/unknown_preset.test.js
new file mode 100644
index 000000000..e2bbad3ef
--- /dev/null
+++ b/test/browser/tests/editor/unknown_preset.test.js
@@ -0,0 +1,23 @@
+import { test } from "../../test_helper.js"
+import { expect } from "@playwright/test"
+
+test.describe("Editor with an unregistered preset", () => {
+ test("connects without crashing and warns about the unknown preset", async ({ page }) => {
+ const pageErrors = []
+ page.on("pageerror", (error) => pageErrors.push(error))
+
+ const warnings = []
+ page.on("console", (message) => {
+ if (message.type() === "warning") warnings.push(message.text())
+ })
+
+ await page.goto("/unknown-preset.html")
+ await page.waitForSelector("lexxy-editor[connected]")
+
+ // It connected (no crash in connectedCallback) and falls back to defaults.
+ await expect(page.locator("lexxy-editor")).toHaveAttribute("connected", "")
+
+ expect(pageErrors, pageErrors.map((e) => e.stack).join("\n\n")).toHaveLength(0)
+ expect(warnings.some((text) => text.includes('Unknown Lexxy preset "not-registered"'))).toBe(true)
+ })
+})