This is an automated email from the ASF dual-hosted git repository. LinkinStars pushed a commit to branch dev in repository https://gitbox.apache.org/repos/asf/answer.git
commit 88c5ef666df0749b2c1a24d464047d48430c6a58 Author: Xan Torres <[email protected]> AuthorDate: Sat Aug 1 19:44:13 2026 +0800 fix: render every entry stylesheet, not only the first GetStyle returned a single stylesheet path because the previous build emitted exactly one. The current build emits two, so server-rendered pages loaded partially unstyled while every build step still reported success. The stylesheet is now a list, mirroring how script paths are already collected and prefixed, and the template renders one link per entry. This is the same assumption as the tag-shape one fixed earlier: the server encoded a property of one bundler's output, here that there is exactly one entry stylesheet. (cherry picked from commit d66e21b252752ef9d231b958e7452e66202ba0f3) --- internal/controller/template_controller.go | 19 ++++++++++++------- internal/controller/template_controller_test.go | 4 ++++ ui/template/header.html | 4 +++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go index 8290d8b6..3c102166 100644 --- a/internal/controller/template_controller.go +++ b/internal/controller/template_controller.go @@ -57,8 +57,11 @@ import ( var SiteUrl = "" type TemplateController struct { - scriptPath []string - cssPath string + scriptPath []string + // cssPath lists every stylesheet the frontend build emits, in document + // order; a build that emits more than one entry stylesheet needs all of + // them, not just the first, or server-rendered pages come back unstyled. + cssPath []string templateRenderController *templaterender.TemplateRenderController siteInfoService siteinfo_common.SiteInfoCommonService eventQueueService eventqueue.Service @@ -85,7 +88,7 @@ func NewTemplateController( questionService: questionService, } } -func GetStyle() (script []string, css string) { +func GetStyle() (script []string, css []string) { file, err := ui.Build.ReadFile("build/index.html") if err != nil { return @@ -131,9 +134,9 @@ func GetStyle() (script []string, css string) { script = append(script, src) } case "link": - if css == "" && isStylesheet(n) { + if isStylesheet(n) { if href, ok := attr(n, "href"); ok && href != "" { - css = href + css = append(css, href) } } } @@ -602,7 +605,7 @@ func (tc *TemplateController) Page404(ctx *gin.Context) { func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteInfo *schema.TemplateSiteInfoResp, data gin.H) { prefix := "" - cssPath := "" + cssPath := make([]string, len(tc.cssPath)) scriptPath := make([]string, len(tc.scriptPath)) _ = plugin.CallCDN(func(fn plugin.CDN) error { @@ -614,7 +617,9 @@ func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteI if prefix[len(prefix)-1:] == "/" { prefix = strings.TrimSuffix(prefix, "/") } - cssPath = prefix + tc.cssPath + for i, path := range tc.cssPath { + cssPath[i] = prefix + path + } for i, path := range tc.scriptPath { scriptPath[i] = prefix + path } diff --git a/internal/controller/template_controller_test.go b/internal/controller/template_controller_test.go index 273b7df8..6b4b4b79 100644 --- a/internal/controller/template_controller_test.go +++ b/internal/controller/template_controller_test.go @@ -53,4 +53,8 @@ func TestGetStyleResolvesBuiltAssets(t *testing.T) { require.NotEmpty(t, css, "no stylesheet href parsed out of %s; server-rendered pages would load unstyled", builtIndexPath) + for i, href := range css { + require.NotEmpty(t, href, + "stylesheet href %d parsed out of %s is empty; server-rendered pages would load unstyled", i, builtIndexPath) + } } diff --git a/ui/template/header.html b/ui/template/header.html index d5d9a18a..f9f0468b 100644 --- a/ui/template/header.html +++ b/ui/template/header.html @@ -34,7 +34,9 @@ <link rel="canonical" href="{{.siteinfo.Canonical}}" /> <link rel="manifest" href="{{$.baseURL}}/manifest.json" /> <link rel="search" type="application/opensearchdescription+xml" href="{{$.baseURL}}/opensearch.xml" title="{{.siteinfo.General.Name}}" /> - <link href="{{.cssPath}}" rel="stylesheet" /> + {{range $path := .cssPath}} + <link href="{{$path}}" rel="stylesheet" /> + {{end}} <link href="{{$.baseURL}}/custom.css" rel="stylesheet" /> <link rel="icon"
