@adobe-commerce/elsie 2.1.0-alpha-20260903123647 → 2.1.0-alpha-20260915145814
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 +36 -1
- package/package.json +2 -2
- package/src/lib/aem/assets.ts +18 -9
- package/src/lib/slot.tsx +43 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @adobe-commerce/elsie
|
|
2
2
|
|
|
3
|
-
## 2.1.0-alpha-
|
|
3
|
+
## 2.1.0-alpha-20260915145814
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -67,6 +67,14 @@
|
|
|
67
67
|
with `undefined` when no error is present, preserving any existing
|
|
68
68
|
association.
|
|
69
69
|
|
|
70
|
+
- d7d0153: Fix an intermittent `insertBefore` crash in AEM Assets image slots
|
|
71
|
+
(`tryRenderAemAssetsImage`/`makeAemAssetsImageSlot`) that surfaced after the
|
|
72
|
+
preact 10.29 bump. The image render into its container was never awaited
|
|
73
|
+
before handing the container to `Slot`'s `replaceWith`, so it could be grafted
|
|
74
|
+
into the DOM before it had any content.
|
|
75
|
+
|
|
76
|
+
See `docs/slot-dom-graft-race.md` for the full trace.
|
|
77
|
+
|
|
70
78
|
- 089ba5c: fix(a11y): prevent dummy update when keyboard focus moves to
|
|
71
79
|
Incrementer buttons and add aria-valuetext for VoiceOver
|
|
72
80
|
- d59c153: Fix `Modal` accessibility: while the modal is open, sibling content
|
|
@@ -89,6 +97,33 @@
|
|
|
89
97
|
COMPANY_CREATE is no longer in the default form-type map. B2B storefronts pass
|
|
90
98
|
`{ b2bEnabled: true }` to `setConfig()` to include it in the configuration
|
|
91
99
|
query.
|
|
100
|
+
- c53497b: Fix `Slot` silently dropping
|
|
101
|
+
`replaceWith`/`appendChild`/`prependChild`/
|
|
102
|
+
`appendSibling`/`prependSibling`/`remove` calls made from a `slot` callback
|
|
103
|
+
that doesn't `return`/`await` its own async work (e.g. a non-`async` callback
|
|
104
|
+
that calls an `async` helper as a bare statement). Previously, nothing was
|
|
105
|
+
left to trigger the render that would have picked up the queued method once
|
|
106
|
+
the slot's normal init-triggered render pass had already completed. `Slot` now
|
|
107
|
+
detects that case and flushes the pending update itself. Existing callers that
|
|
108
|
+
already `return`/`await` their `slot` callback are unaffected.
|
|
109
|
+
|
|
110
|
+
See `docs/slot-dom-graft-race.md` for the full trace.
|
|
111
|
+
|
|
112
|
+
- efcde21: Fix a recurring `insertBefore` crash in `Slot` when content grafted
|
|
113
|
+
via `replaceWith`/`appendChild`/`prependChild` is re-applied on unrelated
|
|
114
|
+
re-renders. `Slot` replays its registered methods on every render pass (by
|
|
115
|
+
design, so `onRender`/`onChange` can react to fresh state), but the grafted
|
|
116
|
+
content's wrapper VNode was rebuilt from scratch on every replay, handing
|
|
117
|
+
Preact a brand new `ref` closure for a DOM node that was already grafted. That
|
|
118
|
+
churn corrupted Preact's internal DOM bookkeeping for the grafted subtree over
|
|
119
|
+
repeated re-renders, especially in components with ongoing state changes. The
|
|
120
|
+
wrapper VNode is now cached per element, so repeated replays reuse the same
|
|
121
|
+
VNode instance and Preact's diff bails out instead of re-touching the subtree.
|
|
122
|
+
|
|
123
|
+
See `docs/slot-dom-graft-race.md` for the full trace, including why an earlier
|
|
124
|
+
attempt at this fix (making `replaceWith` a no-op after its first run) was
|
|
125
|
+
wrong.
|
|
126
|
+
|
|
92
127
|
- a920177: fix(Incrementer): prevent quantity input flicker during in-progress
|
|
93
128
|
typing, and prevent double onValue call when debounce fires before blur
|
|
94
129
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe-commerce/elsie",
|
|
3
|
-
"version": "2.1.0-alpha-
|
|
3
|
+
"version": "2.1.0-alpha-20260915145814",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"description": "Domain Package SDK",
|
|
6
6
|
"engines": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@adobe-commerce/event-bus": "~1.1.1",
|
|
34
34
|
"@adobe-commerce/fetch-graphql": "~1.3.1",
|
|
35
|
-
"@adobe-commerce/recaptcha": "1.3.0-alpha-
|
|
35
|
+
"@adobe-commerce/recaptcha": "1.3.0-alpha-20260915145814",
|
|
36
36
|
"@adobe-commerce/storefront-design": "~1.1.1",
|
|
37
37
|
"@chromatic-com/storybook": "^5",
|
|
38
38
|
"@dropins/build-tools": "~1.2.1"
|
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 (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
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/lib/slot.tsx
CHANGED
|
@@ -146,9 +146,21 @@ export function useSlot<K, V extends HTMLElement>(
|
|
|
146
146
|
});
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
+
const handleLifeCycleRenderRef = useRef<() => Promise<void>>();
|
|
150
|
+
|
|
149
151
|
const _registerMethod = useCallback((cb: Function) => {
|
|
150
152
|
if (typeof cb === 'function') {
|
|
151
153
|
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
|
+
}
|
|
152
164
|
} else {
|
|
153
165
|
console.warn('Skipped: Invalid _registerMethod', cb);
|
|
154
166
|
}
|
|
@@ -157,9 +169,33 @@ export function useSlot<K, V extends HTMLElement>(
|
|
|
157
169
|
// @ts-ignore
|
|
158
170
|
context._registerMethod = _registerMethod;
|
|
159
171
|
|
|
172
|
+
// `onRender`-style registered methods are replayed on every
|
|
173
|
+
// `handleLifeCycleRender` pass (see `_registerMethod`/`methodsRef` above),
|
|
174
|
+
// and `handleLifeCycleRender` always resets `children` to the fallback
|
|
175
|
+
// before replaying them -- so `replaceWith`/`appendChild`/`prependChild`
|
|
176
|
+
// must genuinely re-apply their VNode on every replay, not just once.
|
|
177
|
+
// Without caching, each replay would call `createElement` fresh, handing
|
|
178
|
+
// Preact a brand new VNode (and new `ref` identity) for content that's
|
|
179
|
+
// already grafted, forcing it to detach/reattach the `ref` for no reason.
|
|
180
|
+
// Caching per `elem` means repeat calls return the *same* VNode object;
|
|
181
|
+
// Preact's diff treats `oldVNode === newVNode` as an explicit "unchanged,
|
|
182
|
+
// skip" signal, so it never re-touches the grafted subtree. See
|
|
183
|
+
// docs/slot-dom-graft-race.md.
|
|
184
|
+
const htmlElementVNodeCache = useMemo(
|
|
185
|
+
() => new Map<HTMLElement, VNode<any>>(),
|
|
186
|
+
// `contentTag` isn't read by the factory -- it's a deliberate cache-bust
|
|
187
|
+
// key, so a `contentTag` change starts a fresh cache instead of handing
|
|
188
|
+
// out VNodes built for the old wrapper tag.
|
|
189
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
190
|
+
[contentTag],
|
|
191
|
+
);
|
|
192
|
+
|
|
160
193
|
const _htmlElementToVNode = useCallback(
|
|
161
194
|
(elem: HTMLElement) => {
|
|
162
|
-
|
|
195
|
+
const cached = htmlElementVNodeCache.get(elem);
|
|
196
|
+
if (cached) return cached;
|
|
197
|
+
|
|
198
|
+
const vnode = createElement(
|
|
163
199
|
contentTag,
|
|
164
200
|
{
|
|
165
201
|
'data-slot-html-element': elem.tagName.toLowerCase(),
|
|
@@ -169,8 +205,11 @@ export function useSlot<K, V extends HTMLElement>(
|
|
|
169
205
|
},
|
|
170
206
|
null,
|
|
171
207
|
);
|
|
208
|
+
|
|
209
|
+
htmlElementVNodeCache.set(elem, vnode);
|
|
210
|
+
return vnode;
|
|
172
211
|
},
|
|
173
|
-
[contentTag],
|
|
212
|
+
[contentTag, htmlElementVNodeCache],
|
|
174
213
|
);
|
|
175
214
|
|
|
176
215
|
// @ts-ignore
|
|
@@ -337,6 +376,8 @@ export function useSlot<K, V extends HTMLElement>(
|
|
|
337
376
|
status.current = 'ready';
|
|
338
377
|
}, [children, context, name, props, render, state]);
|
|
339
378
|
|
|
379
|
+
handleLifeCycleRenderRef.current = handleLifeCycleRender;
|
|
380
|
+
|
|
340
381
|
// Initialization
|
|
341
382
|
const handleLifeCycleInit = useCallback(async () => {
|
|
342
383
|
if (!callback) return;
|