Guard editor configuration against an unknown preset - #1187
Open
MatheusRich wants to merge 1 commit into
Open
Conversation
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
force-pushed
the
guard-configuration-against-missing-preset
branch
from
July 8, 2026 16:04
1403a44 to
fddac08
Compare
MatheusRich
marked this pull request as ready for review
July 8, 2026 16:05
Contributor
There was a problem hiding this comment.
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
EditorConfigurationguard that falls back to{}whenLexxy.presets.get(preset)is missing, plus aconsole.warnto 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 {} | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
If a
<lexxy-editor>is initialized with an unregistered preset, it throwsTypeError: Cannot convert undefined or null to objectfromconnectedCallback:Lexxy.presets.get(preset)returns undefined, anddeepMergethen runsObject.entrieson 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 lateLexxy.configurecall is easy to spot.Fixes #1167