@adobe-commerce/elsie 2.1.0-beta.2 → 2.1.0-beta.3

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @adobe-commerce/elsie
2
2
 
3
+ ## 2.1.0-beta.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 3bfb136: Fix an intermittent `insertBefore` crash in AEM Assets image slots
8
+ (`tryRenderAemAssetsImage`/`makeAemAssetsImageSlot`) that surfaced after the
9
+ preact 10.29 bump. The image render into its container was never awaited
10
+ before handing the container to `Slot`'s `replaceWith`, so it could be grafted
11
+ into the DOM before it had any content. See `docs/slot-dom-graft-race.md` for
12
+ the full trace.
13
+
3
14
  ## 2.1.0-beta.2
4
15
 
5
16
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe-commerce/elsie",
3
- "version": "2.1.0-beta.2",
3
+ "version": "2.1.0-beta.3",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "description": "Domain Package SDK",
6
6
  "engines": {
@@ -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 (ctx: RenderContext) => {
241
+ return async (ctx: RenderContext): Promise<void> => {
242
242
  const { wrapper, alias, params, imageProps } = config;
243
243
 
244
244
  if (!imageProps.src) {
@@ -274,17 +274,25 @@ export function makeAemAssetsImageSlot(config: AemAssetsImageSlotConfig) {
274
274
  params: imageComponentParams,
275
275
  };
276
276
 
277
- UI.render(Image, imageComponentProps)(container);
277
+ // Wait for the Image (and any of its own nested slots) to finish
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);
278
286
  ctx.replaceWith(container);
279
287
  };
280
288
  }
281
289
 
282
- export function tryRenderAemAssetsImage(
290
+ export async function tryRenderAemAssetsImage(
283
291
  ctx: RenderContext,
284
292
  config: AemAssetsImageSlotConfig,
285
- ): void {
293
+ ): Promise<void> {
286
294
  // Renders an equivalent of the default image.
287
- function renderDefaultImage(): void {
295
+ async function renderDefaultImage(): Promise<void> {
288
296
  const container = config.wrapper ?? document.createElement('div');
289
297
  const { imageProps, params } = config;
290
298
  const imageComponentProps: ImageProps = {
@@ -293,7 +301,8 @@ export function tryRenderAemAssetsImage(
293
301
  height: params.height,
294
302
  };
295
303
 
296
- UI.render(Image, imageComponentProps)(container);
304
+ // See the comment in `makeAemAssetsImageSlot` above.
305
+ await UI.render(Image, imageComponentProps)(container);
297
306
  ctx.replaceWith(container);
298
307
  }
299
308
 
@@ -301,7 +310,7 @@ export function tryRenderAemAssetsImage(
301
310
 
302
311
  if (!assetsEnabled) {
303
312
  // No-op, render the default image.
304
- renderDefaultImage();
313
+ await renderDefaultImage();
305
314
  return;
306
315
  }
307
316
 
@@ -315,9 +324,9 @@ export function tryRenderAemAssetsImage(
315
324
 
316
325
  if (!isAemAssetsUrl(assetsUrl)) {
317
326
  // Not an AEM Assets URL, so render the default image.
318
- renderDefaultImage();
327
+ await renderDefaultImage();
319
328
  return;
320
329
  }
321
330
 
322
- makeAemAssetsImageSlot(config)(ctx);
331
+ await makeAemAssetsImageSlot(config)(ctx);
323
332
  }