DEV: Simplify ember-cli proxy strategy (#24242)

Previously, the app HTML served by the Ember-CLI proxy was generated based on a 'bootstrap json' payload generated by Rails. This inevitably leads to differences between the Rails HTML and the Ember-CLI HTML.

This commit overhauls our proxying strategy. Now, we totally ignore the ember-cli `index.html` file. Instead, we take the full HTML from Rails and surgically replace script URLs based on a `data-discourse-entrypoint` attribute. This should be faster (only one request to Rails), more robust, and less confusing for developers.
This commit is contained in:
David Taylor
2023-11-10 11:16:06 +00:00
committed by GitHub
parent 80208d0ab6
commit ac896755bb
12 changed files with 348 additions and 710 deletions

View File

@ -142,22 +142,24 @@ module ApplicationHelper
scripts
.map do |name|
path = script_asset_path(name)
preload_script_url(path)
preload_script_url(path, entrypoint: script)
end
.join("\n")
.html_safe
end
def preload_script_url(url)
def preload_script_url(url, entrypoint: nil)
entrypoint_attribute = entrypoint ? "data-discourse-entrypoint=\"#{entrypoint}\"" : ""
add_resource_preload_list(url, "script")
if GlobalSetting.preload_link_header
<<~HTML.html_safe
<script defer src="#{url}"></script>
<script defer src="#{url}" #{entrypoint_attribute}></script>
HTML
else
<<~HTML.html_safe
<link rel="preload" href="#{url}" as="script">
<script defer src="#{url}"></script>
<link rel="preload" href="#{url}" as="script" #{entrypoint_attribute}>
<script defer src="#{url}" #{entrypoint_attribute}></script>
HTML
end
end