apache / apache/answer

Vite migration (1/3): Go HTML and asset contract

Open
#1,579 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
15.7k
Forks
1.4k
Avg merge
3d 8h
Merged PRs (30d)
7

Description

Part of #1578. First step of the series; can land while Create React App still builds.

**Problem.** `internal/controller/template_controller.go` `GetStyle()` scrapes the script and stylesheet paths out of the built `ui/build/index.html` with regexes that require classic scripts with `defer` first and stylesheet links with `href` before `rel`, and it returns a single stylesheet path. Every server-rendered page reuses those paths through `ui/template/header.html`. Any other tag shape returns nothing, and the pages load with no JavaScript and no stylesheet while every build step still reports success. Nothing in the tree asserts the contract.

**Change.** Read the tags from the parsed document (`golang.org/x/net/html`), so attribute order, attribute set and quoting no longer matter. Return `cssPath` as a list, mirroring how script paths are already collected and prefixed, and range over it in `header.html`. Add `TestGetStyleResolvesBuiltAssets`, which calls the real `GetStyle()` against the real embedded build and skips when no build is embedded. Keep the classic `` tag in `header.html`; the module switch belongs to step 2.

**Done when.** `dev` with only this change builds the frontend with the current toolchain, `go build ./...` and `go vet ./...` pass, the test passes against that build, and the served pages are unchanged (one stylesheet, classic scripts).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with internal/controller/template_controller.go and ui/template/header.html, then inspect the new TestGetStyleResolvesBuiltAssets against the embedded build. Run the frontend dev build followed by go build ./..., go vet ./..., and the asset test. Done means parsed asset tags resolve regardless of attribute order, multiple stylesheet paths are rendered, and served pages retain one stylesheet and classic scripts.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, vite
Domain
backend, build-system, frontend
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.