Skip to content

Serve script tags from Vite's development server - #35

Merged
tricknotes merged 2 commits into
mainfrom
dev-server-script-tags
Sep 3, 2026
Merged

Serve script tags from Vite's development server#35
tricknotes merged 2 commits into
mainfrom
dev-server-script-tags

Conversation

@tricknotes

@tricknotes tricknotes commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Summary

include_ember_script_tags always reads the output of ember build, so a Vite-based application served by ember-cli-rails's development server (tricknotes/ember-cli-rails#653) cannot use the asset helpers without opting out of the server with dev_server: false — and with it, out of fast reloads: embedding the app into Rails-owned HTML then requires a full build (8–10 seconds in my measurements) before a change shows up.

When the application is served by the development server, the helper now reads index.html from the server instead of a build directory, and emits the startup tags with root-relative URLs rewritten to absolute URLs on the server — the same rewrite ember-cli-rails applies when it serves the document itself. Nothing is built, so a change to the application is picked up by reloading the page (about 550 ms from change to reflection in my measurements).

Implementation notes

  • The development server is feature-detected with app.respond_to?(:dev_server?), so combinations with older ember-cli-rails releases (which have no development server) keep their current behavior. The development dependency stays on the released ember-cli-rails; the examples covering the new path stand in plain doubles for the development-server API until a release carries it.
  • The tag extraction shared with the build-directory path is factored into vite_startup_tags(html, prefix:). It now also leaves protocol-relative (//) URLs alone.
  • include_ember_stylesheet_tags raises its Vite guidance for development-server applications too: their dist may not exist, so the Vite detection alone would miss them.
  • CHANGELOG.md carries the new behavior under an Unreleased section.

Verification

  • Added helper specs for the new path (URL rewriting, absolute and protocol-relative URLs passed through, the stylesheet-helper error). spec/helpers and spec/lib pass against the released ember-cli-rails: 11 examples, 0 failures.
  • The 3 spec/features examples fail in my environment for browser-setup reasons, identically with and without this change (verified against a baseline), so please rely on CI for them.
  • Verified end to end in a host Rails application: a page whose HTML is owned by Rails emits tags pointing at the development server, the Ember app boots, and a change to app/styles/app.css is served after a plain reload.

🤖 Generated with Claude Code

`include_ember_script_tags` always read the output of `ember build`, so a Vite-based application served by ember-cli-rails's development server (tricknotes/ember-cli-rails#653) could not use the asset helpers without opting out of the server — and with it, out of fast reloads.

When the application is served by the development server (feature-detected, so older ember-cli-rails releases keep their behavior), read `index.html` from the server instead of a build directory and emit the startup tags with root-relative URLs rewritten to absolute URLs on the server, the same way ember-cli-rails serves the document itself.
Nothing is built, so a change to the application is picked up by reloading the page.

The extraction shared with the build-directory path now also leaves protocol-relative (`//`) URLs alone, and `include_ember_stylesheet_tags` raises its Vite guidance for development-server applications too (their `dist` may not exist, so the Vite detection alone would miss them).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@tricknotes
tricknotes force-pushed the dev-server-script-tags branch from 17a46d5 to 7b97a0a Compare September 2, 2026 09:23
Point the development dependency back at the released ember-cli-rails.
The release carries no development-server API, so the examples covering it stand in plain doubles for `EmberCli::App` and `EmberCli::DevServer`; the helper itself already feature-detects the API with `respond_to?`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
tricknotes pushed a commit to tricknotes/ember-cli-rails that referenced this pull request Sep 3, 2026
With the ember-cli-rails-assets release carrying tricknotes/ember-cli-rails-assets#35, `include_ember_script_tags` reads `index.html` from the development server and emits absolute URLs pointing at it, so the helpers no longer require `dev_server: false`.
Update the passages that said the helpers always read the build output.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@tricknotes
tricknotes force-pushed the dev-server-script-tags branch from 912a51c to 5c45178 Compare September 3, 2026 16:07
@tricknotes
tricknotes merged commit a1447e1 into main Sep 3, 2026
8 of 9 checks passed
@tricknotes
tricknotes deleted the dev-server-script-tags branch September 3, 2026 17:26
@tricknotes tricknotes mentioned this pull request Sep 3, 2026
tricknotes pushed a commit to tricknotes/ember-cli-rails that referenced this pull request Sep 3, 2026
With the ember-cli-rails-assets release carrying tricknotes/ember-cli-rails-assets#35, `include_ember_script_tags` reads `index.html` from the development server and emits absolute URLs pointing at it, so the helpers no longer require `dev_server: false`.
Update the passages that said the helpers always read the build output.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
tricknotes pushed a commit to tricknotes/ember-cli-rails that referenced this pull request Sep 4, 2026
With the ember-cli-rails-assets release carrying tricknotes/ember-cli-rails-assets#35, `include_ember_script_tags` reads `index.html` from the development server and emits absolute URLs pointing at it, so the helpers no longer require `dev_server: false`.
Update the passages that said the helpers always read the build output.

Co-Authored-By: Claude Fable 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.

2 participants