Skip to content

Guard editor configuration against an unknown preset - #1187

Open
MatheusRich wants to merge 1 commit into
basecamp:mainfrom
MatheusRich:guard-configuration-against-missing-preset
Open

Guard editor configuration against an unknown preset#1187
MatheusRich wants to merge 1 commit into
basecamp:mainfrom
MatheusRich:guard-configuration-against-missing-preset

Conversation

@MatheusRich

@MatheusRich MatheusRich commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

If a <lexxy-editor> is initialized with an unregistered preset, it throws TypeError: Cannot convert undefined or null to object from connectedCallback: Lexxy.presets.get(preset) returns undefined, and deepMerge then runs Object.entries on it.

This PR handles the missing preset in EditorConfiguration: an unknown preset falls back to an empty object, so the default preset and attribute overrides still apply, and it logs a warning so a typo or a late Lexxy.configure call is easy to spot.

Fixes #1167

If a <lexxy-editor> is initialized with an unregistered preset, it throws
`TypeError: Cannot convert undefined or null to object` from
`connectedCallback`: `Lexxy.presets.get(preset)` returns undefined, and
`deepMerge` then runs `Object.entries` on it.

This commit handles the missing preset in `EditorConfiguration`: an
unknown preset falls back to an empty object, so the default preset and
attribute overrides still apply, and it logs a warning so a typo or a
late `Lexxy.configure` call is easy to spot.

Fixes basecamp#1167
@MatheusRich
MatheusRich force-pushed the guard-configuration-against-missing-preset branch from 1403a44 to fddac08 Compare July 8, 2026 16:04
@MatheusRich
MatheusRich marked this pull request as ready for review July 8, 2026 16:05
Copilot AI review requested due to automatic review settings July 8, 2026 16:05

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens Lexxy’s editor configuration so <lexxy-editor preset="..."> won’t crash during connectedCallback when the preset name isn’t registered, and adds a Playwright regression test covering that behavior.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Changes:

  • Add an EditorConfiguration guard that falls back to {} when Lexxy.presets.get(preset) is missing, plus a console.warn to surface misconfiguration.
  • Add a browser fixture page that initializes an editor with an unregistered preset.
  • Add a Playwright test asserting “no crash + warning emitted” for the unknown preset scenario.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/editor/configuration.js Prevents deepMerge from receiving undefined for unknown presets by falling back to {} and warning.
test/browser/fixtures/unknown-preset.html Fixture page that loads a <lexxy-editor> with preset="not-registered".
test/browser/tests/editor/unknown_preset.test.js Regression test ensuring the editor connects without page errors and logs a warning for an unknown preset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +22 to +31
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 {}
}
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.

Uncaught TypeError: Cannot convert undefined or null to object when focus is programmatically moved away from an editor

2 participants