Skip to content

Commit

Permalink
fix: Canvas crash with Failed to execute 'matches' on 'Element': ':cu…
Browse files Browse the repository at this point in the history
…rrent' 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
  • Loading branch information
istarkov authored Dec 19, 2024
1 parent 2d7cfba commit 41f933e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apps/builder/app/canvas/instance-selected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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`);
}
}

Expand Down

0 comments on commit 41f933e

Please sign in to comment.