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.

reuse the namespace for id

Oleg Isonenb2be37487d15
diff --git a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
index e346c8a7a6..a8458c8359 100644
--- a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
+++ b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
@@ -7,6 +7,7 @@ import {
components,
type Instance,
type OnChangeChildren,
+ idAttribute,
} from "@webstudio-is/react-sdk";
import { useTextEditingInstanceId } from "~/shared/nano-states";
import { useSelectedElement } from "~/canvas/shared/nano-states";
@@ -77,7 +78,7 @@ export const WrapperComponentDev = ({
// for this we need to also make search by id fast
id: instance.id,
"data-ws-component": instance.component,
- "data-ws-id": instance.id,
+ [idAttribute]: instance.id,
onClick: (event: MouseEvent) => {
if (instance.component === "Link") {
event.preventDefault();
diff --git a/apps/designer/app/canvas/shared/styles.ts b/apps/designer/app/canvas/shared/styles.ts
index 323145fca5..81a2cffe30 100644
--- a/apps/designer/app/canvas/shared/styles.ts
+++ b/apps/designer/app/canvas/shared/styles.ts
@@ -13,6 +13,7 @@ import {
Breakpoint,
ValidStaticStyleValue,
validStaticValueTypes,
+ idAttribute,
} from "@webstudio-is/react-sdk";
import { globalCss } from "@webstudio-is/design-system";
import { useEffect } from "react";
@@ -98,7 +99,7 @@ const wrappedRulesMap = new Map<string, StyleRule>();
const addRule = (id: string, cssRule: CssRule) => {
const key = id + cssRule.breakpoint;
- const selectorText = `[data-ws-id="${id}"]`;
+ const selectorText = `[${idAttribute}="${id}"]`;
const rule = cssEngine.addStyleRule(selectorText, {
...cssRule,
style: toVarStyleWithFallback(id, cssRule.style),
diff --git a/apps/designer/app/routes/s/css.ts b/apps/designer/app/routes/s/css.ts
index 098924ea01..5165138e46 100644
--- a/apps/designer/app/routes/s/css.ts
+++ b/apps/designer/app/routes/s/css.ts
@@ -6,6 +6,7 @@ import env from "~/env.server";
import { sentryException } from "~/shared/sentry";
import { createCssEngine } from "@webstudio-is/css-engine";
import { getCssRules } from "~/shared/tree-utils";
+import { idAttribute } from "@webstudio-is/react-sdk";
export const loader: ActionFunction = async ({ request }) => {
try {
@@ -39,7 +40,7 @@ export const loader: ActionFunction = async ({ request }) => {
const cssRules = getCssRules(canvasData.tree?.root);
for (const [instanceId, cssRule] of cssRules) {
- engine.addStyleRule(`[data-ws-id="${instanceId}"]`, cssRule);
+ engine.addStyleRule(`[${idAttribute}="${instanceId}"]`, cssRule);
}
const { cssText } = engine;
diff --git a/packages/react-sdk/src/tree/wrapper-component.tsx b/packages/react-sdk/src/tree/wrapper-component.tsx
index a362f5839a..fa775a717d 100644
--- a/packages/react-sdk/src/tree/wrapper-component.tsx
+++ b/packages/react-sdk/src/tree/wrapper-component.tsx
@@ -39,9 +39,10 @@ export const WrapperComponent = ({
}: WrapperComponentProps) => {
const { Component } = components[instance.component];
const userProps = useUserProps(instance.id);
+ const props = { ...userProps, ...rest, [idAttribute]: instance.id };
return (
- <Component {...userProps} {...rest} data-ws-id={instance.id}>
- {renderWrapperComponentChildren(children)}
- </Component>
+ <Component {...props}>{renderWrapperComponentChildren(children)}</Component>
);
};
+
+export const idAttribute = "data-ws-id";