@adobe-commerce/elsie 2.1.0-beta.4 → 2.1.0-beta.6
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 +42 -0
- package/package.json +2 -2
- package/src/lib/aem/assets.ts +9 -18
- package/src/lib/slot.tsx +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# @adobe-commerce/elsie
|
|
2
2
|
|
|
3
|
+
## 2.1.0-beta.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 406a36d: Restore the existing Slot implementation and temporarily downgrade
|
|
8
|
+
Preact from 10.29 to 10.28.4, the latest pre-10.29 release, to avoid
|
|
9
|
+
intermittent `insertBefore` crashes in AEM Asset image Slots while the
|
|
10
|
+
underlying DOM graft and render-root ownership changes are developed and
|
|
11
|
+
validated separately.
|
|
12
|
+
|
|
13
|
+
## 2.1.0-beta.5
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 4cc7219: Fix a memory leak in `Slot`'s VNode cache (added to fix repeated
|
|
18
|
+
`insertBefore` crashes from replay churn): entries were never pruned, so a
|
|
19
|
+
`slot` callback that keeps calling `replaceWith`/`appendChild`/`prependChild`
|
|
20
|
+
with newly constructed elements over time (rather than mutating one element in
|
|
21
|
+
place) would pin every historical element in memory for the Slot's whole
|
|
22
|
+
lifetime. Entries are now evicted via the grafted element's `ref` callback
|
|
23
|
+
firing with `null`, which Preact does precisely when that VNode is detached
|
|
24
|
+
(superseded by a different element, or the Slot unmounting).
|
|
25
|
+
|
|
26
|
+
See `docs/slot-dom-graft-race.md` for the full trace, including a
|
|
27
|
+
pre-existing, unrelated gap this surfaced: calling `replaceWith` a second time
|
|
28
|
+
with a different element doesn't remove the first one.
|
|
29
|
+
|
|
30
|
+
- ba3bbe7: Fix a recurring `insertBefore` crash in `Slot` when content grafted
|
|
31
|
+
via `replaceWith`/`appendChild`/`prependChild` is re-applied on unrelated
|
|
32
|
+
re-renders. `Slot` replays its registered methods on every render pass (by
|
|
33
|
+
design, so `onRender`/`onChange` can react to fresh state), but the grafted
|
|
34
|
+
content's wrapper VNode was rebuilt from scratch on every replay, handing
|
|
35
|
+
Preact a brand new `ref` closure for a DOM node that was already grafted. That
|
|
36
|
+
churn corrupted Preact's internal DOM bookkeeping for the grafted subtree over
|
|
37
|
+
repeated re-renders, especially in components with ongoing state changes. The
|
|
38
|
+
wrapper VNode is now cached per element, so repeated replays reuse the same
|
|
39
|
+
VNode instance and Preact's diff bails out instead of re-touching the subtree.
|
|
40
|
+
|
|
41
|
+
See `docs/slot-dom-graft-race.md` for the full trace, including why an earlier
|
|
42
|
+
attempt at this fix (making `replaceWith` a no-op after its first run) was
|
|
43
|
+
wrong.
|
|
44
|
+
|
|
3
45
|
## 2.1.0-beta.4
|
|
4
46
|
|
|
5
47
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe-commerce/elsie",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.6",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"description": "Domain Package SDK",
|
|
6
6
|
"engines": {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"identity-obj-proxy": "^3.0.0",
|
|
88
88
|
"jest": "^30.4.2",
|
|
89
89
|
"jest-environment-jsdom": "^30.0.0",
|
|
90
|
-
"preact": "~10.
|
|
90
|
+
"preact": "~10.28.4",
|
|
91
91
|
"preact-i18n": "2.4.0-preactx",
|
|
92
92
|
"preact-render-to-string": "^5.1.4",
|
|
93
93
|
"prettier": "^3.8.4",
|
package/src/lib/aem/assets.ts
CHANGED
|
@@ -238,7 +238,7 @@ export function tryGenerateAemAssetsOptimizedUrl(
|
|
|
238
238
|
|
|
239
239
|
/** Creates a slot that renders an AEM Assets image. */
|
|
240
240
|
export function makeAemAssetsImageSlot(config: AemAssetsImageSlotConfig) {
|
|
241
|
-
return
|
|
241
|
+
return (ctx: RenderContext) => {
|
|
242
242
|
const { wrapper, alias, params, imageProps } = config;
|
|
243
243
|
|
|
244
244
|
if (!imageProps.src) {
|
|
@@ -274,25 +274,17 @@ export function makeAemAssetsImageSlot(config: AemAssetsImageSlotConfig) {
|
|
|
274
274
|
params: imageComponentParams,
|
|
275
275
|
};
|
|
276
276
|
|
|
277
|
-
|
|
278
|
-
// rendering into `container` before handing it to `ctx.replaceWith`.
|
|
279
|
-
// Slot grafts `container` into the DOM via an imperative `ref` callback
|
|
280
|
-
// that Preact's own diffing doesn't track (see docs/slot-dom-graft-race.md)
|
|
281
|
-
// -- handing it over before it has content means it gets grafted empty,
|
|
282
|
-
// then mutated again later outside Preact's bookkeeping, which is what
|
|
283
|
-
// was corrupting Preact's internal DOM pointers and causing sporadic
|
|
284
|
-
// `insertBefore` crashes after the preact 10.29 bump.
|
|
285
|
-
await UI.render(Image, imageComponentProps)(container);
|
|
277
|
+
UI.render(Image, imageComponentProps)(container);
|
|
286
278
|
ctx.replaceWith(container);
|
|
287
279
|
};
|
|
288
280
|
}
|
|
289
281
|
|
|
290
|
-
export
|
|
282
|
+
export function tryRenderAemAssetsImage(
|
|
291
283
|
ctx: RenderContext,
|
|
292
284
|
config: AemAssetsImageSlotConfig,
|
|
293
|
-
):
|
|
285
|
+
): void {
|
|
294
286
|
// Renders an equivalent of the default image.
|
|
295
|
-
|
|
287
|
+
function renderDefaultImage(): void {
|
|
296
288
|
const container = config.wrapper ?? document.createElement('div');
|
|
297
289
|
const { imageProps, params } = config;
|
|
298
290
|
const imageComponentProps: ImageProps = {
|
|
@@ -301,8 +293,7 @@ export async function tryRenderAemAssetsImage(
|
|
|
301
293
|
height: params.height,
|
|
302
294
|
};
|
|
303
295
|
|
|
304
|
-
|
|
305
|
-
await UI.render(Image, imageComponentProps)(container);
|
|
296
|
+
UI.render(Image, imageComponentProps)(container);
|
|
306
297
|
ctx.replaceWith(container);
|
|
307
298
|
}
|
|
308
299
|
|
|
@@ -310,7 +301,7 @@ export async function tryRenderAemAssetsImage(
|
|
|
310
301
|
|
|
311
302
|
if (!assetsEnabled) {
|
|
312
303
|
// No-op, render the default image.
|
|
313
|
-
|
|
304
|
+
renderDefaultImage();
|
|
314
305
|
return;
|
|
315
306
|
}
|
|
316
307
|
|
|
@@ -324,9 +315,9 @@ export async function tryRenderAemAssetsImage(
|
|
|
324
315
|
|
|
325
316
|
if (!isAemAssetsUrl(assetsUrl)) {
|
|
326
317
|
// Not an AEM Assets URL, so render the default image.
|
|
327
|
-
|
|
318
|
+
renderDefaultImage();
|
|
328
319
|
return;
|
|
329
320
|
}
|
|
330
321
|
|
|
331
|
-
|
|
322
|
+
makeAemAssetsImageSlot(config)(ctx);
|
|
332
323
|
}
|
package/src/lib/slot.tsx
CHANGED
|
@@ -146,21 +146,9 @@ export function useSlot<K, V extends HTMLElement>(
|
|
|
146
146
|
});
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
-
const handleLifeCycleRenderRef = useRef<() => Promise<void>>();
|
|
150
|
-
|
|
151
149
|
const _registerMethod = useCallback((cb: Function) => {
|
|
152
150
|
if (typeof cb === 'function') {
|
|
153
151
|
methodsRef.current.push(cb);
|
|
154
|
-
|
|
155
|
-
// If the slot already finished its normal init-triggered render pass
|
|
156
|
-
// (status is back to 'ready'), nothing else will flush this method.
|
|
157
|
-
// This happens when an async `slot` callback doesn't `return`/`await`
|
|
158
|
-
// its own async work before calling replaceWith/appendChild/etc. --
|
|
159
|
-
// `handleLifeCycleInit` moves on before this method gets registered.
|
|
160
|
-
// Flush it ourselves rather than silently dropping it.
|
|
161
|
-
if (status.current === 'ready') {
|
|
162
|
-
handleLifeCycleRenderRef.current?.();
|
|
163
|
-
}
|
|
164
152
|
} else {
|
|
165
153
|
console.warn('Skipped: Invalid _registerMethod', cb);
|
|
166
154
|
}
|
|
@@ -349,8 +337,6 @@ export function useSlot<K, V extends HTMLElement>(
|
|
|
349
337
|
status.current = 'ready';
|
|
350
338
|
}, [children, context, name, props, render, state]);
|
|
351
339
|
|
|
352
|
-
handleLifeCycleRenderRef.current = handleLifeCycleRender;
|
|
353
|
-
|
|
354
340
|
// Initialization
|
|
355
341
|
const handleLifeCycleInit = useCallback(async () => {
|
|
356
342
|
if (!callback) return;
|