Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Load the Prism worker from the static route

9a9e708c1def7250086e612cdee88e1ea12298ab · Keenan Nemetz · 21d ago · parent 7c02af12

Load the Prism worker from the static route

The highlighting script asked for /static/prism-worker.js, but every browser
asset is served under /-/static/. The request fell through to the HTML 404 page,
so the browser refused the worker for its MIME type and every blob stayed plain.

HTMX also compiles an hx-trigger filter with Function(), which script-src 'self'
blocks. The two polling triggers used a visibility filter for that; drop the
filter, pause the request in app.js while the tab is hidden, and turn eval off in
the HTMX config so a future filter is caught instead of failing in production.

Tests hold the worker to its route and the templates to trigger forms that do
not need eval.

server/web/highlight_test.go +15

@@ -61,6 +61,21 @@ func TestPrismWorkerDisablesPrismOwnMessageHandler(t *testing.T) {
61 61 }
62 62 }
63 63
64 // The worker is a static asset, so app.js must name it under /-/static/. A bare
65 // /static/ URL is not a route: the catch-all answers with the HTML 404 page, and
66 // the browser refuses that worker for its MIME type, leaving every blob plain
67 // with nothing else failing.
68 func TestPrismWorkerUsesTheStaticAssetRoute(t *testing.T) {
69 t.Parallel()
70 source, err := os.ReadFile("static/app.js")
71 if err != nil {
72 t.Fatal(err)
73 }
74 if !strings.Contains(string(source), "new Worker('/-/static/prism-worker.js')") {
75 t.Fatal("app.js does not load the Prism worker from /-/static/prism-worker.js")
76 }
77 }
78
64 79 // A worker that goes back to importing every grammar up front still colours
65 80 // correctly, so nothing else fails: the page just pays 565 KB and a few hundred
66 81 // milliseconds again. This is the assertion that notices.