Skip to content

[No QA] Add a Cloudflare Worker that serves the web build with Workers Static Assets - #103501

Merged
justinpersaud merged 28 commits into
mainfrom
jpersaud-newdot-static-assets-worker
Oct 13, 2026
Merged

justinpersaud merged 28 commits into
mainfrom
jpersaud-newdot-static-assets-worker

Conversation

@justinpersaud

@justinpersaud justinpersaud commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Moving the app deployment/build into Cloudlare Static Workers from Cloudfront S3.

This is handling that and deploying it to a new subdomain so we can test it out.

Fixed Issues

For https://github.com/Expensify/Expensify/issues/688126
PROPOSAL:

Tests

I deployed this to https://test-staging.new.expensify.com

  • Verify that no errors appear in the JS console

Offline tests

  1. With npm run dev -- --local-protocol https running, load https://localhost:8787/ once so the service worker activates.
  2. In DevTools > Network, set throttling to Offline and reload.
  3. Verify the app still opens from the service worker cache.

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

No QA. Nothing is deployed and the web app is still built and served the same way.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Standalone npm package (not a root workspace) so wrangler and workerd stay out of the root install. Root ESLint and Knip skip it because its types live in its own node_modules.
font-src uses 'self' instead of a hard-coded host, so the same policy works on localhost and test hostnames.
Missing static files return 404 instead of the SPA shell, hashed assets are cached as immutable, and HTML is never revalidated because its CSP nonce changes per request.
HTML responses never carry ETag or Last-Modified, so browsers have no validator to send for them.
Runs the real wrangler.jsonc in workerd via wrangler's createTestHarness against a fixture build, using node:test so the package needs no test-runner dependency.
The asset router 307-redirects paths like /a/[email protected] to its own percent-encoding. Looking assets up with that encoding keeps the URL the user opened.
Diffs status, caching and security headers (CSP per directive, nonces masked) between two hosts, e.g. production and a local wrangler dev session.
Covers running the Worker in workerd with wrangler dev against a real web build, the automated and manual checks, and what can only be verified on a deployed hostname.
The Worker is a standalone package that root typecheck and tests do not cover. The job needs no secrets, so it is safe on fork PRs.
CI installs Node from the root .nvmrc, so an exact engines pin here would fail npm ci on every Node upgrade.
wrangler dev and wrangler deploy now run scripts/prepareDist.sh themselves, so a deploy cannot upload source maps or Brotli twins by skipping a manual step.
The Worker runs for every asset request, so logging every request would far exceed the included Workers Logs volume.
Node's fetch replaces Sec-Fetch-Mode with the request mode, so the tests never sent a navigation. Miniflare restores MF-Sec-Fetch-Mode as Sec-Fetch-Mode before the Worker runs.
…shes

Covers the .<10 hex>. naming scheme and files that must not be cached as immutable, the navigation exception to the missing-file 404, and checks every inline script in web/index.html without a nonce against the CSP hashes.
wrangler types also runs the build command, and CI has no dist/. Without one, dev and deploy still fail on the missing assets directory.
The fixture files were named like build output, which made it look as though compiled assets were committed. The harness now writes the same files into its temporary directory.
The staging environment is reserved for staging.new.expensify.com, so it has no route until the switchover. test-staging serves a staging build with the staging CSP on its own Worker.
The file has no extension, so a miss fell through to the SPA shell and was then served as application/json.
The tests check its inline scripts against the CSP hashes, so an edit there needs them to run.
Node's fetch overwrites Sec-Fetch-Mode, so the script's navigation checks reached a local Worker as ordinary requests.
A rebuild deletes dist/.assetsignore, so prepare-dist has to run again. Release archives now download to /tmp so they can't be committed.
Runs alongside the S3 deploy with a token that can only edit the test-staging Worker. continue-on-error keeps a failure there from failing the staging deploy.
@justinpersaud
justinpersaud marked this pull request as ready for review October 9, 2026 17:58
@justinpersaud
justinpersaud requested review from a team as code owners October 9, 2026 17:58
@melvin-bot
melvin-bot Bot requested a review from dylanexpensify October 9, 2026 17:58
@justinpersaud
justinpersaud requested review from AndrewGable and removed request for dylanexpensify October 9, 2026 17:58
@melvin-bot
melvin-bot Bot removed the request for review from a team October 9, 2026 17:58
@justinpersaud
justinpersaud requested review from a team and roryabraham October 9, 2026 17:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T18:27:42.531488Z c917dce Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@melvin-bot
melvin-bot Bot requested a review from JmillsExpensify October 9, 2026 17:58
@justinpersaud
justinpersaud requested review from coleaeason and removed request for JmillsExpensify October 9, 2026 17:58
@melvin-bot
melvin-bot Bot requested review from NicolasBonet and removed request for a team October 9, 2026 17:58
@melvin-bot

melvin-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

@NicolasBonet Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@NicolasBonet NicolasBonet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c917dcef08

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +77 to +79
if (HASHED_ASSET_PATH.test(url.pathname)) {
response.headers.set('Cache-Control', 'public, max-age=31536000, immutable');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid caching missing hashed assets as immutable

When an old tab requests a hashed chunk absent from the current deployment, the asset binding returns the non-HTML 404 exercised in tests/worker.test.ts:149-155, but this unconditional pathname check still assigns that error max-age=31536000, immutable. The browser can retain the negative response for a year, so rolling back or otherwise reintroducing that same content-hashed asset will not recover for affected clients; apply the immutable policy only to successful asset responses.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎🏽

@justinpersaud

Copy link
Copy Markdown
Contributor Author

Looks like Rory and Cole are actually OOO so I'm going to merge this.

@justinpersaud
justinpersaud merged commit 06e4f39 into main Oct 13, 2026
50 of 51 checks passed
@justinpersaud
justinpersaud deleted the jpersaud-newdot-static-assets-worker branch October 13, 2026 12:49
@github-actions

Copy link
Copy Markdown
Contributor

🚧 justinpersaud has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/justinpersaud in version: 9.5.9-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/cristipaval in version: 9.5.9-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants