fix(uve): open file-asset links in a new tab instead of loading them as pages (#35504) - #36925
Open
dsilvam wants to merge 1 commit into
Open
fix(uve): open file-asset links in a new tab instead of loading them as pages (#35504)#36925dsilvam wants to merge 1 commit into
dsilvam wants to merge 1 commit into
Conversation
…as pages (#35504) handleInternalNav treated every same-host link as an HTMLPage and fed it to the Page API, so a link to a PDF resolved to a 404 "Page not found" in both edit and preview mode. Add an isAssetPath() predicate that mirrors the backend extension heuristic, and route hrefs resolving to a file asset to a new tab instead. Refs: #35504, FD #36746 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
isAssetPath()to the UVE utils — a predicate that distinguishes file-asset URLs from HTMLPage URLs. It matches dotCMS asset-delivery prefixes (/dA/,/dotAsset/,/contentAsset/) and otherwise mirrors the backend's own extension heuristic inIdentifier#setURI: no extension (or the configuredVELOCITY_PAGE_EXTENSION) means a page, any other real extension means a file.handleInternalNav— a same-host href that resolves to a file asset now opens in a new tab and callspreventDefault(), instead of being handed touveStore.pageLoad().Root cause
handleInternalNavsplit anchor clicks into exactly two buckets: different hostname → open a new tab; anything else →uveStore.pageLoad({ url: url.pathname, ... }). There was no check for whether the same-host target was actually an HTMLPage, so a link to a file asset (/dA/<inode>/fileAsset/doc.pdf,/application/files/doc.pdf) was fed to the Page API, which cannot resolve it. The editor then rendered its "Nothing Live Here Yet" / "Page not found" state.Because the
(internalNav)binding is unconditional, this affected Preview/Published mode as well as Edit mode — the linked issue is titled edit-mode-only, so please exercise both when testing.Checklist
Security note: the new branch passes the already-resolved same-origin
hreftowindow.open. The external-host branch above it is unchanged and still handles cross-origin links, so this does not widen what can be opened; it only changes how same-origin file links are handled. No new user input is parsed —isAssetPathreceives aURL.pathnamethat was already constructed upstream.Test coverage
utils.spec.ts— 19 cases onisAssetPath:/dA/.../report.pdf,/dA/with no extension,/dotAsset/,/contentAsset/,/application/files/report.pdf,.docx,.mp4,.tar.gz, uppercase.PDF/about-us/index,.html,.htm,.dot,/blog/,//blog/release-v1.2and/news/2024.10must stay pages — a naive extension check would read the trailing2/10as a file extension and break navigation to URL-map slugsedit-ema-editor.component.spec.ts— 3 cases onhandleInternalNav: a.pdflink and a/dA/link each open a new tab, callpreventDefault, and do not callpageLoad; an.htmllink still routes throughpageLoad.Full suite: 37/37 suites, 913 passed, 0 failures.
nx lint portlets-edit-ema-portletclean.Additional Info
Verified manually against a locally built image: clicking
/dA/<inode>/fileAsset/<name>.pdfin edit mode now opens the PDF in a new tab and leaves the editor on the page.Note for reviewers/QA: the Angular bundle ships from the separate
dotcms-core-webMaven module, so./mvnw install -pl :dotcms-core -DskipTestswithout--amwill silently test a stale frontend. Use./mvnw install -pl :dotcms-core --am -DskipTests.Two related items deliberately left out of scope:
edit-ema-editor.component.ts, theurl.hostname !== window.location.hostnamecase) opens a new tab but never callspreventDefault(), so an external link also navigates the iframe away. Same class of bug, one line, but unrelated to this issue./dA/would still be treated as a page. Not reachable through the reported flow; a fully authoritative fix would need a backend round-trip per link click.Refs: #35504, FD #36746