Skip to content

Remap a mounted Vite build's asset URLs onto the mount point - #666

Merged
tricknotes merged 1 commit into
mainfrom
remap-mounted-assets
Sep 4, 2026
Merged

Remap a mounted Vite build's asset URLs onto the mount point#666
tricknotes merged 1 commit into
mainfrom
remap-mounted-assets

Conversation

@tricknotes

@tricknotes tricknotes commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Summary

The index.html of a Vite build refers to its assets with root-relative URLs. When mount_ember_app served the build output (Deploy::File) from a path other than /, the document was returned as-is, so the browser requested /assets/... from the Rails root and got a 404 — or another application mounted there. Classic builds have the documented rootURL escape hatch, and include_ember_script_tags remaps via its prepend: option, but mount_ember_app / render_ember_app had no equivalent.

  • mount_ember_app records its mount point as a route default (ember_mount_point, alongside the existing ember_app), render_ember_app passes it to App#index_html (new optional mount_point: keyword — existing callers are unaffected), and the document's root-relative src / href values are remapped onto the mount point, where mount_ember_assets serves the build output
  • References that already carry the mount point — a rootURL configured to match it — are left alone, as are protocol-relative and absolute URLs, classic builds, and development-server-backed documents (their asset URLs point at the development server absolutely, so there is nothing left to remap)
  • README: document the remapping in the "Mounting multiple Ember applications" section, scoping the rootURL walkthrough to classic builds; CHANGELOG entry under the unreleased section

Verification

  • New App#index_html examples cover the remap, the already-prefixed/protocol-relative/absolute skips, the root mount, and classic builds
  • New feature scenario asserts the dummy's /no-block/ document references its scripts under /no-block/ (previously they leaned on the second copy of the application mounted at /)
  • spec/lib passes (the one local failure is the known Chrome-dependent App#test example, green on CI); the js: false feature scenarios pass locally, including the trailing-slash redirects

The `index.html` of a Vite build refers to its assets with root-relative URLs.
When `mount_ember_app` served the build output from a path other than `/`,
the document was returned as-is,
so the browser requested `/assets/...` from the Rails root and got a 404 —
or another application mounted there.
Classic builds have the documented `rootURL` escape hatch,
and `include_ember_script_tags` remaps via its `prepend:` option,
but `mount_ember_app` / `render_ember_app` had no equivalent.

`mount_ember_app` now records its mount point as a route default,
`render_ember_app` passes it to `App#index_html`,
and the document's root-relative `src` / `href` values are remapped onto the mount point,
where `mount_ember_assets` serves the build output.
References that already carry the mount point — a `rootURL` configured to match it — are left alone,
as are classic builds and development-server-backed documents
(their asset URLs point at the development server absolutely).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@tricknotes
tricknotes merged commit 3ca207a into main Sep 4, 2026
20 of 24 checks passed
@tricknotes
tricknotes deleted the remap-mounted-assets branch September 4, 2026 12:13
@tricknotes tricknotes mentioned this pull request Sep 4, 2026
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.

2 participants