Skip to content

Commit 4466e89

Browse files
fix(review): address all code-review findings from PR #262
- Remove duplicate 'Wholesale rebuild' comment block in layer.ts - Harden normalizeLegacyPayload pass-through: check obj.kind !== undefined/null instead of an explicit known-kinds allowlist that needs updating per new kind - Add whenWindowId() non-reject warning + isParentReachable() guard pattern to docs/use-from-a-plugin.md and docs/examples/iframe-initiated-window.md Co-authored-by: Daniel López Sánchez (prismiwi2015) <AllTerrainDeveloper@users.noreply.github.com>
1 parent 0f2c016 commit 4466e89

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

docs/examples/iframe-initiated-window.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ function PreviewSidebar() {
6868
const [ streaming, setStreaming ] = useState( false );
6969

7070
const open = async () => {
71-
// We need to know our own window id so we can include it in
72-
// diagnostics or sub-topic names. `whenWindowId()` resolves
73-
// once the parent has handshaken (always before any user
74-
// interaction in practice).
71+
// Guard before awaiting the window id. `whenWindowId()` never
72+
// rejects — if the parent shell never sends a handshake (e.g.
73+
// cross-origin parent, page opened outside Desktop Mode) the
74+
// Promise hangs forever. `isParentReachable()` resolves that
75+
// ambiguity synchronously.
76+
if ( ! wp.desktop.iframe.isParentReachable() ) {
77+
return; // Not running inside Desktop Mode — bail silently.
78+
}
7579
const myWindowId = await wp.desktop.iframe.whenWindowId();
7680

7781
// Tell the parent shell to open a Preview window paired with us.

docs/use-from-a-plugin.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ We could. We deliberately don't, because:
8787

8888
If you genuinely need a registry-based install (e.g. a CI runner that can't see this repo's filesystem), open an issue and we'll re-evaluate.
8989

90+
## Iframe bridge gotcha — `whenWindowId()` never rejects
91+
92+
If your plugin code runs inside a chromeless wp-admin iframe and calls
93+
`wp.desktop.iframe.whenWindowId()`, be aware that the returned Promise
94+
**never rejects**. When the page is not running inside Desktop Mode (a
95+
cross-origin parent, a direct admin URL visit, a unit-test harness) the
96+
Promise simply hangs forever — any `await` after it will never resume.
97+
98+
Always guard with `isParentReachable()` first:
99+
100+
```javascript
101+
if ( ! wp.desktop.iframe.isParentReachable() ) {
102+
return; // Not inside Desktop Mode — skip iframe-bridge code.
103+
}
104+
const windowId = await wp.desktop.iframe.whenWindowId();
105+
```
106+
107+
The same caveat applies to `Window.whenContentReady()` on the shell side —
108+
it never rejects if the content iframe never signals readiness.
109+
90110
## Troubleshooting
91111

92112
- **`Cannot find module 'desktop-mode'`** — confirm the `file:` path is correct relative to your plugin's `package.json` location, then re-run `npm install`.

src/desktop-files/layer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,6 @@ export function mountFilesLayer( host: HTMLElement, folderId = 0 ): FilesLayer {
534534
return;
535535
}
536536

537-
// Wholesale rebuild — last resort. Pin-flag flips, parent-
538-
// folder moves, file-type changes, all land here. Plugins
539-
// that want stable decorations re-attach via `tile-rendered`.
540-
541537
// Wholesale rebuild — last-resort path for transitions the
542538
// incremental walker can't handle (pin-flag flips, parent-
543539
// folder moves, file-type changes). Plugins that want stable

src/drag-bridge.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,7 @@ function normalizeLegacyPayload(
160160
string,
161161
unknown
162162
>;
163-
if (
164-
obj.kind === 'attachment' ||
165-
obj.kind === 'post' ||
166-
obj.kind === 'user'
167-
) {
163+
if ( obj.kind !== undefined && obj.kind !== null ) {
168164
return payload;
169165
}
170166
// Look-alike test for the legacy Media Library payload — id +

0 commit comments

Comments
 (0)