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

## Description

closes #4622



## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
0000)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
This commit is contained in:
Ivan Starkov authored and GitHub committed 2024-12-19 18:40:14 +03:00
1 parent 2d7cfba8a4
commit 41f933ef4d
1 file changed
+8 -2
+8 -2
View File
@@ -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`);
}
}