Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: Canvas crash with Failed to execute 'matches' on 'Element': ':current' is not a valid selector. (#4623)

Ivan Starkov41f933ef4d5c
diff --git a/apps/builder/app/canvas/instance-selected.ts b/apps/builder/app/canvas/instance-selected.ts
index abb6d0bf57..e807665758 100644
--- a/apps/builder/app/canvas/instance-selected.ts
+++ b/apps/builder/app/canvas/instance-selected.ts
@@ -31,6 +31,7 @@ import {
import { getBrowserStyle } from "./features/webstudio-component/get-browser-style";
import type { InstanceSelector } from "~/shared/tree-utils";
import { shallowEqual } from "shallow-equal";
+import warnOnce from "warn-once";
const isHtmlTag = (tag: string): tag is HtmlTags =>
htmlTags.includes(tag as HtmlTags);
@@ -233,8 +234,13 @@ const subscribeSelectedInstance = (
}
const activeStates = new Set<string>();
for (const state of availableStates) {
- if (element.matches(state)) {
- activeStates.add(state);
+ try {
+ // pseudo classes like :open or :current are not supported in .matches method
+ if (element.matches(state)) {
+ activeStates.add(state);
+ }
+ } catch {
+ warnOnce(true, `state selector "${state}" is invalid`);
}
}