@snowcone-app/ui 0.10.14 → 0.10.16
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/CHANGELOG.md +18 -0
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/personalization/PersonalizationProvider.tsx +7 -3
- package/src/personalization/__tests__/PersonalizationProvider.canvas-import.test.tsx +35 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowcone-app/ui",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.16",
|
|
4
4
|
"description": "React components for merchandise visualization and customization",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"react-instantsearch": "^7.15.5",
|
|
104
104
|
"react-zoom-pan-pinch": "^3.6.4",
|
|
105
105
|
"tailwind-merge": "^3.0.0",
|
|
106
|
-
"@snowcone-app/sdk": "0.
|
|
106
|
+
"@snowcone-app/sdk": "0.31.0"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
109
|
"@chromatic-com/storybook": "^4.1.2",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"@vitejs/plugin-react": "^4.7.0",
|
|
122
122
|
"@vueless/storybook-dark-mode": "^10.0.3",
|
|
123
123
|
"jsdom": "^24.1.0",
|
|
124
|
-
"next": "16.4.
|
|
124
|
+
"next": "16.4.6",
|
|
125
125
|
"react": "^18.3.1",
|
|
126
126
|
"react-dom": "^18.3.1",
|
|
127
127
|
"rimraf": "^6.1.2",
|
|
@@ -186,7 +186,8 @@ export interface PersonalizationProviderProps {
|
|
|
186
186
|
} | null;
|
|
187
187
|
/**
|
|
188
188
|
* Lazy import for `@snowcone-app/canvas`. Runs in the consumer's webpack context
|
|
189
|
-
* so module resolution works even though this package doesn't depend on canvas.
|
|
189
|
+
* so module resolution works even though this package doesn't depend on canvas. Called only when `fields` is
|
|
190
|
+
* non-empty: a product without personalization never loads the canvas.
|
|
190
191
|
*
|
|
191
192
|
* @example `canvasImport={() => import("@snowcone-app/canvas")}`
|
|
192
193
|
*/
|
|
@@ -249,9 +250,12 @@ export function PersonalizationProvider({
|
|
|
249
250
|
cachedBridgeComponent,
|
|
250
251
|
);
|
|
251
252
|
|
|
253
|
+
// Only a product with personalization fields renders through the hidden canvas, so only then is the canvas
|
|
254
|
+
// imported (it is most of a product page's JS: www's PDP shipped it to every product until 2026-11).
|
|
255
|
+
const hasFields = fields.length > 0;
|
|
252
256
|
useEffect(() => {
|
|
253
257
|
if (CanvasComponent && BridgeComponent) return;
|
|
254
|
-
if (!canvasImport) return;
|
|
258
|
+
if (!canvasImport || !hasFields) return;
|
|
255
259
|
|
|
256
260
|
// Reuse in-flight promise if another instance already started loading
|
|
257
261
|
if (!canvasLoadPromise) {
|
|
@@ -271,7 +275,7 @@ export function PersonalizationProvider({
|
|
|
271
275
|
setBridgeComponent(() => cachedBridgeComponent);
|
|
272
276
|
}
|
|
273
277
|
});
|
|
274
|
-
}, [CanvasComponent, BridgeComponent, canvasImport]);
|
|
278
|
+
}, [CanvasComponent, BridgeComponent, canvasImport, hasFields]);
|
|
275
279
|
|
|
276
280
|
// --- Realtime connection (lazy — only on first export) ---
|
|
277
281
|
const realtimeEnabledRef = useRef(false);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PersonalizationProvider imports @snowcone-app/canvas only for a product with personalization fields: the canvas is
|
|
3
|
+
* most of a product page's JS (www's PDP shipped it to every product until 2026-11, E_PDP_EAGER_EDITOR in www).
|
|
4
|
+
*/
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { render, waitFor } from "@testing-library/react";
|
|
7
|
+
import { describe, expect, it, vi } from "vitest";
|
|
8
|
+
import { PersonalizationProvider } from "../PersonalizationProvider";
|
|
9
|
+
|
|
10
|
+
describe("PersonalizationProvider canvasImport", () => {
|
|
11
|
+
it("never imports the canvas for a product without personalization fields", async () => {
|
|
12
|
+
const canvasImport = vi.fn(() => Promise.resolve({}));
|
|
13
|
+
render(
|
|
14
|
+
<PersonalizationProvider fields={[]} canvasImport={canvasImport} lazy>
|
|
15
|
+
<p>page</p>
|
|
16
|
+
</PersonalizationProvider>,
|
|
17
|
+
);
|
|
18
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
19
|
+
expect(canvasImport).not.toHaveBeenCalled();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("imports it when the product has personalization fields", async () => {
|
|
23
|
+
const canvasImport = vi.fn(() => Promise.resolve({}));
|
|
24
|
+
render(
|
|
25
|
+
<PersonalizationProvider
|
|
26
|
+
fields={[{ type: "text", name: "Name", label: "Name" } as never]}
|
|
27
|
+
canvasImport={canvasImport}
|
|
28
|
+
lazy
|
|
29
|
+
>
|
|
30
|
+
<p>page</p>
|
|
31
|
+
</PersonalizationProvider>,
|
|
32
|
+
);
|
|
33
|
+
await waitFor(() => expect(canvasImport).toHaveBeenCalledTimes(1));
|
|
34
|
+
});
|
|
35
|
+
});
|