@webstudio-is/react-sdk 0.199.0 → 0.201.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/runtime.js CHANGED
@@ -167,12 +167,41 @@ var PageSettingsTitle = (props) => {
167
167
  return /* @__PURE__ */ jsx2("title", { ...localProps });
168
168
  };
169
169
 
170
+ // src/page-settings-canonical-link.tsx
171
+ import { useEffect as useEffect3, useState as useState4 } from "react";
172
+ import { jsx as jsx3 } from "react/jsx-runtime";
173
+ var isServer3 = typeof window === "undefined";
174
+ var PageSettingsCanonicalLink = (props) => {
175
+ const [localProps, setLocalProps] = useState4();
176
+ useEffect3(() => {
177
+ const selector = `head > link[rel="canonical"]`;
178
+ let allLinks = document.querySelectorAll(selector);
179
+ for (const meta of allLinks) {
180
+ if (!isElementRenderedWithReact(meta)) {
181
+ meta.remove();
182
+ }
183
+ }
184
+ allLinks = document.querySelectorAll(selector);
185
+ if (allLinks.length === 0) {
186
+ setLocalProps(props);
187
+ }
188
+ }, [props]);
189
+ if (isServer3) {
190
+ return /* @__PURE__ */ jsx3("link", { rel: "canonical", ...props });
191
+ }
192
+ if (localProps === void 0) {
193
+ return;
194
+ }
195
+ return /* @__PURE__ */ jsx3("link", { rel: "canonical", ...localProps });
196
+ };
197
+
170
198
  // src/runtime.ts
171
199
  var xmlNodeTagSuffix = "-ws-xml-node-fb77f896-8e96-40b9-b8f8-90a4e70d724a";
172
200
  var getIndexWithinAncestorFromComponentProps = (props) => {
173
201
  return props["data-ws-index"];
174
202
  };
175
203
  export {
204
+ PageSettingsCanonicalLink,
176
205
  PageSettingsMeta,
177
206
  PageSettingsTitle,
178
207
  ReactSdkContext,
@@ -49,7 +49,6 @@ export declare const namespaceMeta: (meta: WsComponentMeta, namespace: string, c
49
49
  } | undefined;
50
50
  }[] | undefined;
51
51
  indexWithinAncestor?: string | undefined;
52
- stylable?: boolean | undefined;
53
52
  icon: string;
54
53
  presetStyle?: import("@webstudio-is/sdk").PresetStyle;
55
54
  };
@@ -0,0 +1,17 @@
1
+ type PageSettingsCanonicalLinkProps = {
2
+ href: string;
3
+ };
4
+ /**
5
+ * Link canonical tag are deduplicated on the server using the HTMLRewriter interface.
6
+ * This is not full deduplication. We simply skip rendering Page Setting link
7
+ * if it has already been rendered using HeadSlot/HeadLink.
8
+ * To prevent React on the client from re-adding the removed link tag, we skip rendering them client-side.
9
+ * This approach works because React retains server-rendered link tag as long as they are not re-rendered by the client.
10
+ *
11
+ * The following component behavior ensures this:
12
+ * 1. On the server: Render link tag as usual.
13
+ * 2. On the client: Before rendering, remove any link tag with the same `name` or `property` that were not rendered by Client React,
14
+ * and then proceed with rendering as usual.
15
+ */
16
+ export declare const PageSettingsCanonicalLink: (props: PageSettingsCanonicalLinkProps) => import("react/jsx-runtime").JSX.Element | undefined;
17
+ export {};
@@ -3,6 +3,7 @@ export * from "./hook";
3
3
  export * from "./variable-state";
4
4
  export { PageSettingsMeta } from "./page-settings-meta";
5
5
  export { PageSettingsTitle } from "./page-settings-title";
6
+ export { PageSettingsCanonicalLink } from "./page-settings-canonical-link";
6
7
  /**
7
8
  * React has issues rendering certain elements, such as errors when a <link> element has children.
8
9
  * To render XML, we wrap it with an <svg> tag and add a suffix to avoid React's default behavior on these elements.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.199.0",
3
+ "version": "0.201.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -14,8 +14,8 @@
14
14
  "type-fest": "^4.32.0",
15
15
  "vitest": "^3.0.2",
16
16
  "zod": "^3.22.4",
17
- "@webstudio-is/tsconfig": "1.0.7",
18
- "@webstudio-is/template": "0.199.0"
17
+ "@webstudio-is/template": "0.201.0",
18
+ "@webstudio-is/tsconfig": "1.0.7"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "react": "18.3.0-canary-14898b6a9-20240318",
@@ -26,11 +26,11 @@
26
26
  "change-case": "^5.4.4",
27
27
  "html-tags": "^4.0.0",
28
28
  "nanoid": "^5.0.9",
29
- "@webstudio-is/css-engine": "0.199.0",
30
- "@webstudio-is/icons": "^0.199.0",
31
- "@webstudio-is/sdk": "0.199.0",
32
- "@webstudio-is/image": "0.199.0",
33
- "@webstudio-is/fonts": "0.199.0"
29
+ "@webstudio-is/css-engine": "0.201.0",
30
+ "@webstudio-is/fonts": "0.201.0",
31
+ "@webstudio-is/icons": "^0.201.0",
32
+ "@webstudio-is/image": "0.201.0",
33
+ "@webstudio-is/sdk": "0.201.0"
34
34
  },
35
35
  "exports": {
36
36
  ".": {