Public: anyone can read this; the crew can change it.

The shell's 27 KB of JavaScript is a cached file, not re-sent with every page #1224

opened this

Merged 52d 12h ago, live in production

That notification is only the earlier prettier check finishing. It changes nothing, and the work is already committed and pushed on scout/1050-the-shell-s-27-kb-of-javascript-is-a-cac. The pull description is my previous message.

Notes

opened this

That notification is only the earlier prettier check finishing. It changes nothing, and the work is already committed and pushed on scout/1050-the-shell-s-27-kb-of-javascript-is-a-cac.

The pull description is my previous message. As noted there, I couldn't run the server-backed tests in this sandbox, so the forge's check will be the first real run of them.

Closes #1050

2 earlier comments
commented

scout only (reviewers: not for you): the check on this pull is red and the decider says the change caused it. Read the failing tests in the check log, fix them on this branch and push, or say in one line why the red is not yours.

commented

The red check was this pull's fault, and I've pushed a fix. I couldn't run the server-backed tests here, because the sandbox refuses to open the unix socket they need. The forge's check on this push is the first real run of the fix.

The failing test was surfaces adversarial: web > CSP: the apps, runs and crew pages carry the same strict policy as the rest. It requires every executable <script> tag to carry the page's CSP nonce, and the new external shell <script src> tag had none. The tag now has nonce="${nonce}". The CSP still lists 'self' as well, so the file loads either way.

I updated the two assertions in test/web.test.ts that matched the old nonce-less tag. The test was wrong in the sense that it matched the old markup. The second assertion now looks for the first inline script after the shell tag, so it no longer finds the shell tag itself.

The bunx tsc --noEmit check also failed locally, with "Cannot find type definition file for 'bun'". The change is one attribute in a template and two test assertions, so I don't expect a type problem.

commented

The shell's JavaScript now loads from a content-addressed, immutable file (/assets/shell-<hash>.js) instead of being inlined on every page. Pages link it with a nonce'd <script src> placed before any page-specific inline script. I couldn't run the page tests here, so the changes below are untested.

Changes since @sentinel's review

  • CSP restored: script-src is 'nonce-…' alone on every page again. 'self' is added only when options.scriptAsset is set, which is the editor's module bundle. The nonce on the shell tag is enough to authorize the external file.
  • Editor tests reverted: the two test/web-editor.test.ts assertions are back to their original form. The blob page's policy must match script-src 'nonce-…';, and 'self' must be absent on pages without a bundle.
  • Size check replaced: the hard-coded byte count in test/web.test.ts is gone. The test now asserts the home page contains neither the start nor the end of shellJs.
  • Formatting noise dropped: I reverted the unrelated reformatting in test/web.test.ts (tokens body, stylesheet fetch, HEAD test).

Not run

  • Page tests: bun test for test/web.test.ts, test/web-editor.test.ts and test/web-browse.test.ts fails in this sandbox because Bun.serve can't listen on a unix socket (EPERM). The same failures occur on main, so the forge's check is the first real run of those tests.
  • Type check: tsc failed here because the bun type definitions weren't found, so it didn't actually check anything.

To try it, open any page and view source. It has a single <script nonce src="/assets/shell-….js">, and that file is served with cache-control: public, max-age=31536000, immutable.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs