Repository navigation
fix: make installing libraries from the library browser work - #1436
scottscott wants to merge 2 commits into
Conversation
Clicking "Add to your Excalidraw" on libraries.excalidraw.com silently did nothing: the site navigates back to the referrer URL with an "addLibrary" fragment, but the configured libraryReturnUrl was the Files app URL (the editor runs inside the viewer), which mounts no editor that handles the fragment via useHandleLibrary. Add a standalone editor page (PageController::standalone) that boots the editor outside the Files app and point libraryReturnUrl at it, so the return navigation loads an editor, imports the library and persists it through the existing onLibraryChange flow. Public shares keep the previous behavior: the standalone page needs a session-authenticated user. Part of nextcloud#26
The initial library load replaces the library wholesale (merge: false) and its effect re-fires when fileName/isLoading settle, wiping any library imported via an addLibrary URL fragment (or otherwise added) after the first load. Handle addLibrary fragments only once the initial load has finished, and make the load effect idempotent per file/editor instance so late dependency changes cannot re-run the wholesale replace. File changes still reset the load via the existing fileId-change effect. Part of nextcloud#26
Update: second race fixed (the wipe)While verifying the standalone page end-to-end I found a second race that caused libraries installed from the browser to appear and then vanish within a second. This was actually the original symptom in #26, and it's why the earlier fix looked right in the code but still wiped on the real deployment. Root causeThe initial library load in On top of that, Fix (second commit,
|
Symptom
Library → "Browse libraries" → "Add to your Excalidraw" on libraries.excalidraw.com silently does nothing. The library is neither imported into the session nor persisted.
Root cause
libraries.excalidraw.com does not push libraries via
postMessage; its "Add" button is a link back to the referrer URL with anaddLibraryfragment ({referrer}#addLibrary={libraryUrl}, or?addLibrary=withoutuseHash). The receiving app is expected to handle that fragment — excalidraw.com does this viauseHandleLibrary, and this app already calls it inApp.tsx.The problem is
libraryReturnUrl: the editor runs inside the Files app viewer (no iframe, no dedicated URL), sowindow.location.hrefis the Files app URL. The "Add" link therefore loads the Files app with anaddLibraryfragment in a new tab — a page that mounts no Excalidraw editor and never runsuseHandleLibrary. Silent no-op, on both the legacy viewer (NC ≤ 35) and the new viewer element (NC 36+).Fix
GET /apps/whiteboard/standalone/{fileId}(PageController::standalone) that renders the existingdirectEditingtemplate with a server-generated JWT and astandalonePageinitial-state flag;main.tsgains a matching runtime that boots the editor into#whiteboard-appoutside the Files app.libraryReturnUrlnow points at that page (absolute URL, still passed pre-encoded for the browse-button template). On return from the libraries site, the editor boots,useHandleLibraryimports the library (prompting for confirmation since the instance token differs), and the existingonLibraryChange→updateLibraryItemsflow persists it server-side./apps/whiteboard/standalonesoconnect-src https://libraries.excalidraw.comapplies there (the libraries origin was already whitelisted for whiteboard pages; the new path just wasn't matched byisWhiteboardPage()).Tested
npm run build,eslint src/App.tsx src/main.ts,php -lon changed files.referrer=…/apps/whiteboard/standalone/{fileId}.standalone/{fileId}#addLibrary=…; clicking it loads the standalone editor.Part of #26 (libraries did not persist across reloads at all; this fix wires the import path into the server-backed library store).