From 41f933ef4d5c0768dab76e0e4400246d85aaf181 Mon Sep 17 00:00:00 2001 From: Ivan Starkov Date: Thu, 19 Dec 2024 18:40:14 +0300 Subject: [PATCH] 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 --- apps/builder/app/canvas/instance-selected.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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(); 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`); } }