Skip to content

Keep assets hosted outside the build out of the asset lookup - #43

Merged
tricknotes merged 1 commit into
mainfrom
pass-through-remote-assets
Sep 18, 2026
Merged

tricknotes merged 1 commit into
mainfrom
pass-through-remote-assets

Conversation

@tricknotes

@tricknotes tricknotes commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

Fixes #25.

Since assets are resolved from dist/index.html, every <script src> and <link rel="stylesheet" href> in that document is looked up in the build output by its basename.
A document may also point at assets that the build does not produce, such as a stylesheet served by a font service or a script served by a CDN.
Those have no entry in the build output, so the lookup raises Failed to find assets matching, and an inline <script> without a src raises a TypeError from File.basename(nil).

Changes

  • Add EmberCli::Assets::Url.remote?, which recognizes a URL that resolves outside the build: one carrying a scheme (https://example.com/app.css), and a protocol-relative one (//example.com/app.css)
  • Emit such a URL from EmberCli::Assets::AssetMap as it is, and skip a tag that references no asset at all (an inline <script>)
  • Stop joining prepend onto those URLs in the helpers: prepend mounts the build output onto a path or another host, so it only applies to the URLs that point into the build. This matches how the Vite startup tags are already remapped

Verification

spec/lib and spec/helpers pass (16 examples).
The five new examples fail without the change: three raise from the lookup (two BuildError, one TypeError) and two show prepend joined onto a remote URL.
The spec/features suite, which builds a real Ember application, was not run here.

Since assets are resolved from `dist/index.html`, every `<script src>` and `<link rel="stylesheet" href>` in that document is looked up in the build output by its basename.
A document may also point at assets that the build does not produce, such as a stylesheet served by a font service or a script served by a CDN.
Those have no entry in the build output, so the lookup raised `Failed to find assets matching`, and an inline `<script>` without a `src` raised a `TypeError` from `File.basename(nil)`.

Emit a URL that resolves outside the build (one carrying a scheme, or a protocol-relative one) as it is, and skip a tag that references no asset at all.
`prepend` mounts the build output onto a path or another host, so it no longer applies to those URLs either, matching how the Vite startup tags are already remapped.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@tricknotes
tricknotes marked this pull request as ready for review September 18, 2026 00:40
@tricknotes
tricknotes merged commit 97a93d5 into main Sep 18, 2026
10 checks passed
@tricknotes
tricknotes deleted the pass-through-remote-assets branch September 18, 2026 00:40
@tricknotes tricknotes mentioned this pull request Sep 18, 2026
tricknotes pushed a commit to tricknotes/ember-cli-rails that referenced this pull request Sep 18, 2026
A built `index.html` may point at assets the build does not produce, such as a
stylesheet served by a font service or a script served by a CDN.
They have no file to resolve against, and an inline `<script>` names no asset at
all, so resolving every reference by its basename fails on both.

Emit a URL that resolves outside the build as it is, and skip a tag that carries
no URL.
`prepend` mounts the build output onto a path or another host, so the readers
take it and join it only onto the assets that point into the build, the way
`startup_tags` already remaps a Vite build.

This carries the behaviour the asset helpers gained in
tricknotes/ember-cli-rails-assets#43 into the code that now interprets the
build, and `StartupTags` shares the predicate that decides it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

PR #15 breaks on stylesheets not in the local filesystem

2 participants