Skip to content

feat(loadfile): request directory contents via new iframe API#10

Merged
den-sq merged 1 commit into
ChengLabResearch:mainfrom
tavateva:feat/directory-request-api
Jul 7, 2026
Merged

feat(loadfile): request directory contents via new iframe API#10
den-sq merged 1 commit into
ChengLabResearch:mainfrom
tavateva:feat/directory-request-api

Conversation

@tavateva

@tavateva tavateva commented Jul 7, 2026

Copy link
Copy Markdown

Closes #9.

Depends on ouroboros #114 (merged) which added the request/response iframe API.

Problem

Since ouroboros #106, send-directory-contents arrives with nodes: {}. The plugin's LoadFile modal renders an empty list — Object.values(directoryData.data.nodes).map(...) sees nothing.

What changed

Wire up the new API in src/App/index.tsx:

  • On each send-directory-contents (root change), dispatch a request-directory-contents with recursive: true and a monotonic requestId (`loadfile-N`).
  • Track the active requestId in a ref; drop late responses whose id doesn't match, so a response for a previous root can't clobber the current tree.
  • On send-directory-contents-response, merge data.nodes back into directoryData so LoadFile's existing tree renderer works again without changes.
  • Guard the merge with a data.path === current directoryPath check — belt-and-suspenders against the same out-of-order case.
  • Handle error.code:
    • denied / not-found / internal → empty tree (matches the existing "no files" rendering).
    • internal also logs via console.error.
    • limit with truncated: true → render the partial nodes the response carries. The truncation hint UI is deferred as a follow-up so this diff stays surgical.

LoadFile itself is unchanged.

Verify

  • npx tsc -b — clean (typecheck passes).
  • npm run build — clean.
  • npm run lint — pre-existing lint errors in the repo (288, mostly @ts-nocheck and no-explicit-any in NG viewer code, unrelated to this change). No new errors introduced (identical count on `main` vs. this branch).

Manual UI smoke against a running Ouroboros not performed here — no display on the automation host. Reviewer checklist for a live test:

  1. Open Ouroboros, load the neuroglancer plugin, and Open Folder → a small directory.
  2. LoadFile modal should populate with the folder tree.
  3. Change root folder → tree updates to the new root.
  4. Rapid root changes → no stale-tree flicker (thanks to requestId matching).
  5. Load against a folder large enough to hit the enumeration cap → partial tree renders, no crash.

Not changed

  • Message-handling structure elsewhere (`send-neuroglancer-json`, `read-file-response`, save flow) is untouched.
  • Autoseg plugin doesn't need this — it doesn't use parent-window directory messaging.

Followup

If desired, surface `error.truncated: true` in the LoadFile UI (e.g., "showing partial tree") — separate small PR.

…hengLabResearch#9)

ouroboros #106 stopped broadcasting the recursive file tree in
send-directory-contents, so the plugin's LoadFile modal has been
rendering an empty list. ouroboros #114 (merged) added a
request-directory-contents / send-directory-contents-response pair
scoped per requesting iframe.

Wire it up in App:

- On send-directory-contents (root change), dispatch a
  request-directory-contents with recursive:true and a monotonic
  requestId (loadfile-N).
- Track the active requestId in a ref; drop responses whose id does not
  match, so late responses from a previous root can't clobber current
  state.
- On send-directory-contents-response, merge data.nodes back into
  directoryData so LoadFile's existing tree renderer sees the tree
  again without other changes.
- Error handling: denied / not-found / internal → empty tree (matches
  the existing 'no files' rendering); limit → render the partial nodes
  the response carried (truncated hint deferred as follow-up).
- Guard the merge with a path check so an out-of-order response for a
  previous root can't overwrite the new root's tree.

LoadFile itself unchanged. Verified: tsc -b, npm run build. Manual UI
smoke against a running Ouroboros not run here — see PR body.
@den-sq den-sq merged commit 5991634 into ChengLabResearch:main Jul 7, 2026
1 check passed
@tavateva tavateva deleted the feat/directory-request-api branch July 7, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate LoadFile to request-directory-contents API (unblocks post-#106 file discovery)

2 participants