Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/builder/app/shared/html.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,23 @@ test("generate Image component instead of img element", () => {
)
);
});

test("strip unsupported attribute names", () => {
expect(
generateFragmentFromHtml(`
<button @click="open = true">Expand</button>
<button x-on:click="open = !open">
Toggle
</button>
`)
).toEqual(
renderTemplate(
<>
<ws.element ws:tag="button">Expand</ws.element>
<ws.element ws:tag="button" x-on:click="open = !open">
Toggle
</ws.element>
</>
)
);
});
5 changes: 5 additions & 0 deletions apps/builder/app/shared/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ariaAttributes, attributesByTag } from "@webstudio-is/html-data";
import { camelCaseProperty, parseCss } from "@webstudio-is/css-data";
import { richTextContentTags } from "./content-model";
import { setIsSubsetOf } from "./shim";
import { isAttributeNameSafe } from "@webstudio-is/react-sdk";

type ElementNode = DefaultTreeAdapterMap["element"];

Expand Down Expand Up @@ -169,6 +170,10 @@ export const generateFragmentFromHtml = (
}
instances.set(instance.id, instance);
for (const attr of node.attrs) {
// skip attributes which cannot be rendered in jsx
if (!isAttributeNameSafe(attr.name)) {
continue;
}
const id = `${instance.id}:${attr.name}`;
const instanceId = instance.id;
const name = attr.name;
Expand Down