From 2b5deb5725bd8f3a1e490a72347c0b6f301839e8 Mon Sep 17 00:00:00 2001 From: Brooks Lybrand Date: Wed, 16 Jul 2025 11:09:13 -0500 Subject: [PATCH 1/4] Remove menu collapse middleware --- .github/workflows/deploy.production.yml | 138 ++++++++++++------------ app/pages/docs-layout.tsx | 4 +- app/pages/healthcheck.tsx | 19 +--- 3 files changed, 73 insertions(+), 88 deletions(-) diff --git a/.github/workflows/deploy.production.yml b/.github/workflows/deploy.production.yml index 5f7090c5..34a67a98 100644 --- a/.github/workflows/deploy.production.yml +++ b/.github/workflows/deploy.production.yml @@ -2,7 +2,7 @@ name: 🚀 Deploy (production) on: push: branches: - - main + - brooks/fix-caching paths-ignore: - "README.md" @@ -14,65 +14,65 @@ env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} jobs: - lint: - name: ⬣ ESLint - runs-on: ubuntu-latest - steps: - - name: ⬇️ Checkout repo - uses: actions/checkout@v4 - - - name: ⎔ Setup node - uses: actions/setup-node@v4 - with: - cache: npm - cache-dependency-path: ./package-lock.json - node-version: 22 - - - name: 📥 Install deps - run: npm install - - - name: 🔬 Lint - run: npm run lint - - typecheck: - name: ʦ TypeScript - runs-on: ubuntu-latest - steps: - - name: ⬇️ Checkout repo - uses: actions/checkout@v4 - - - name: ⎔ Setup node - uses: actions/setup-node@v4 - with: - cache: npm - cache-dependency-path: ./package-lock.json - node-version: 22 - - - name: 📥 Install deps - run: npm install - - - name: 🔎 Type check - run: npm run typecheck --if-present - - vitest: - name: ⚡ Vitest - runs-on: ubuntu-latest - steps: - - name: ⬇️ Checkout repo - uses: actions/checkout@v4 - - - name: ⎔ Setup node - uses: actions/setup-node@v4 - with: - cache: npm - cache-dependency-path: ./package-lock.json - node-version: 22 - - - name: 📥 Install deps - run: npm install - - - name: ⚡ Run vitest - run: npm run test -- --coverage + # lint: + # name: ⬣ ESLint + # runs-on: ubuntu-latest + # steps: + # - name: ⬇️ Checkout repo + # uses: actions/checkout@v4 + + # - name: ⎔ Setup node + # uses: actions/setup-node@v4 + # with: + # cache: npm + # cache-dependency-path: ./package-lock.json + # node-version: 22 + + # - name: 📥 Install deps + # run: npm install + + # - name: 🔬 Lint + # run: npm run lint + + # typecheck: + # name: ʦ TypeScript + # runs-on: ubuntu-latest + # steps: + # - name: ⬇️ Checkout repo + # uses: actions/checkout@v4 + + # - name: ⎔ Setup node + # uses: actions/setup-node@v4 + # with: + # cache: npm + # cache-dependency-path: ./package-lock.json + # node-version: 22 + + # - name: 📥 Install deps + # run: npm install + + # - name: 🔎 Type check + # run: npm run typecheck --if-present + + # vitest: + # name: ⚡ Vitest + # runs-on: ubuntu-latest + # steps: + # - name: ⬇️ Checkout repo + # uses: actions/checkout@v4 + + # - name: ⎔ Setup node + # uses: actions/setup-node@v4 + # with: + # cache: npm + # cache-dependency-path: ./package-lock.json + # node-version: 22 + + # - name: 📥 Install deps + # run: npm install + + # - name: ⚡ Run vitest + # run: npm run test -- --coverage deploy: name: 🚀 Deploy @@ -86,16 +86,16 @@ jobs: uses: superfly/flyctl-actions/setup-flyctl@1.5 - name: 🚀 Deploy Production - if: ${{ github.ref == 'refs/heads/main' }} + if: ${{ github.ref == 'refs/heads/brooks/fix-caching' }} run: flyctl deploy --remote-only --config ./fly.production.toml --build-arg COMMIT_SHA=${{ github.sha }} env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - purge: - name: 🧹 Purge CDN - runs-on: ubuntu-latest - needs: [deploy] - steps: - - name: 🧹 Purge All - run: | - curl -D - -X POST --location "https://api.fastly.com/service/${{ secrets.FASTLY_SERVICE_ID }}/purge_all" -H "Accept: application/json" -H "Fastly-Key: ${{ secrets.FASTLY_API_TOKEN }}" -H "fastly-soft-purge: 1" + # purge: + # name: 🧹 Purge CDN + # runs-on: ubuntu-latest + # needs: [deploy] + # steps: + # - name: 🧹 Purge All + # run: | + # curl -D - -X POST --location "https://api.fastly.com/service/${{ secrets.FASTLY_SERVICE_ID }}/purge_all" -H "Accept: application/json" -H "Fastly-Key: ${{ secrets.FASTLY_API_TOKEN }}" -H "fastly-soft-purge: 1" diff --git a/app/pages/docs-layout.tsx b/app/pages/docs-layout.tsx index eb1445a1..297349e0 100644 --- a/app/pages/docs-layout.tsx +++ b/app/pages/docs-layout.tsx @@ -16,12 +16,12 @@ import { useCodeBlockCopyButton } from "~/ui/utils"; import { menuCollapseContext, - menuCollapseStateMiddleware, + // menuCollapseStateMiddleware, } from "~/actions/menu-collapse/server"; import docsCss from "~/styles/docs.css?url"; -export let unstable_middleware = [menuCollapseStateMiddleware]; +// export let unstable_middleware = [menuCollapseStateMiddleware]; export async function loader({ request, params, context }: Route.LoaderArgs) { let url = new URL(request.url); diff --git a/app/pages/healthcheck.tsx b/app/pages/healthcheck.tsx index 2828a064..c9f4c607 100644 --- a/app/pages/healthcheck.tsx +++ b/app/pages/healthcheck.tsx @@ -1,20 +1,5 @@ // learn more: https://fly.io/docs/reference/configuration/#services-http_checks -import type { LoaderFunction } from "react-router"; -export const loader: LoaderFunction = async ({ request }) => { - // const host = - // request.headers.get("X-Forwarded-Host") ?? request.headers.get("host"); - - // try { - // const url = new URL("/", `http://${host}`); - // await Promise.all([ - // fetch(url.toString(), { method: "HEAD" }).then((r) => { - // if (!r.ok) return Promise.reject(r); - // }), - // ]); +export async function loader() { return new Response("OK"); - // } catch (error: unknown) { - // console.log("healthcheck ❌", { error }); - // return new Response("ERROR", { status: 500 }); - // } -}; +} From 65e269fcb4cc7a7fe1d57f98d0a5f910673093cf Mon Sep 17 00:00:00 2001 From: Brooks Lybrand Date: Wed, 16 Jul 2025 11:09:45 -0500 Subject: [PATCH 2/4] remove job dependencies --- .github/workflows/deploy.production.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.production.yml b/.github/workflows/deploy.production.yml index 34a67a98..58047598 100644 --- a/.github/workflows/deploy.production.yml +++ b/.github/workflows/deploy.production.yml @@ -77,7 +77,7 @@ jobs: deploy: name: 🚀 Deploy runs-on: ubuntu-latest - needs: [lint, typecheck, vitest] + # needs: [lint, typecheck, vitest] steps: - name: ⬇️ Checkout repo uses: actions/checkout@v4 From d2df4ffc0ebcb7e734c4a93f16769f136596aaa0 Mon Sep 17 00:00:00 2001 From: Brooks Lybrand Date: Wed, 16 Jul 2025 11:34:06 -0500 Subject: [PATCH 3/4] Check that the state has changed before committing setting the cookie --- app/actions/menu-collapse/server.ts | 30 +++++++++++++++++++++++++++-- app/pages/docs-layout.tsx | 4 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/actions/menu-collapse/server.ts b/app/actions/menu-collapse/server.ts index e046c8bd..9ad18d5e 100644 --- a/app/actions/menu-collapse/server.ts +++ b/app/actions/menu-collapse/server.ts @@ -51,17 +51,43 @@ export let menuCollapseStateMiddleware: unstable_MiddlewareFunction< let res = await next(); + // If the state hasn't changed, don't set the cookie + // the state could be changed by the menu collapse action + let currentState = menuCollapse.get(); + if (statesEqual(menuCollapseCookieState, currentState)) { + return res; + } + res.headers.append( "Set-Cookie", await cookie.serialize({ - // Check the context again, because it could be mutated by the action - menuCollapseState: menuCollapse.get(), + menuCollapseState: currentState, }), ); return res; }; +function statesEqual( + state1: MenuCollapseState, + state2: MenuCollapseState, +): boolean { + const keys1 = Object.keys(state1); + const keys2 = Object.keys(state2); + + if (keys1.length !== keys2.length) { + return false; + } + + for (const key of keys1) { + if (state1[key] !== state2[key]) { + return false; + } + } + + return true; +} + async function parseMenuCollapseState( request: Request, ): Promise { diff --git a/app/pages/docs-layout.tsx b/app/pages/docs-layout.tsx index 297349e0..eb1445a1 100644 --- a/app/pages/docs-layout.tsx +++ b/app/pages/docs-layout.tsx @@ -16,12 +16,12 @@ import { useCodeBlockCopyButton } from "~/ui/utils"; import { menuCollapseContext, - // menuCollapseStateMiddleware, + menuCollapseStateMiddleware, } from "~/actions/menu-collapse/server"; import docsCss from "~/styles/docs.css?url"; -// export let unstable_middleware = [menuCollapseStateMiddleware]; +export let unstable_middleware = [menuCollapseStateMiddleware]; export async function loader({ request, params, context }: Route.LoaderArgs) { let url = new URL(request.url); From 3e328a531eeba8fc9379dc6381d93936722184d9 Mon Sep 17 00:00:00 2001 From: Brooks Lybrand Date: Wed, 16 Jul 2025 12:04:31 -0500 Subject: [PATCH 4/4] Reset deploy script --- .github/workflows/deploy.production.yml | 140 ++++++++++++------------ 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/.github/workflows/deploy.production.yml b/.github/workflows/deploy.production.yml index 58047598..5f7090c5 100644 --- a/.github/workflows/deploy.production.yml +++ b/.github/workflows/deploy.production.yml @@ -2,7 +2,7 @@ name: 🚀 Deploy (production) on: push: branches: - - brooks/fix-caching + - main paths-ignore: - "README.md" @@ -14,70 +14,70 @@ env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} jobs: - # lint: - # name: ⬣ ESLint - # runs-on: ubuntu-latest - # steps: - # - name: ⬇️ Checkout repo - # uses: actions/checkout@v4 - - # - name: ⎔ Setup node - # uses: actions/setup-node@v4 - # with: - # cache: npm - # cache-dependency-path: ./package-lock.json - # node-version: 22 - - # - name: 📥 Install deps - # run: npm install - - # - name: 🔬 Lint - # run: npm run lint - - # typecheck: - # name: ʦ TypeScript - # runs-on: ubuntu-latest - # steps: - # - name: ⬇️ Checkout repo - # uses: actions/checkout@v4 - - # - name: ⎔ Setup node - # uses: actions/setup-node@v4 - # with: - # cache: npm - # cache-dependency-path: ./package-lock.json - # node-version: 22 - - # - name: 📥 Install deps - # run: npm install - - # - name: 🔎 Type check - # run: npm run typecheck --if-present - - # vitest: - # name: ⚡ Vitest - # runs-on: ubuntu-latest - # steps: - # - name: ⬇️ Checkout repo - # uses: actions/checkout@v4 - - # - name: ⎔ Setup node - # uses: actions/setup-node@v4 - # with: - # cache: npm - # cache-dependency-path: ./package-lock.json - # node-version: 22 - - # - name: 📥 Install deps - # run: npm install - - # - name: ⚡ Run vitest - # run: npm run test -- --coverage + lint: + name: ⬣ ESLint + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: ⎔ Setup node + uses: actions/setup-node@v4 + with: + cache: npm + cache-dependency-path: ./package-lock.json + node-version: 22 + + - name: 📥 Install deps + run: npm install + + - name: 🔬 Lint + run: npm run lint + + typecheck: + name: ʦ TypeScript + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: ⎔ Setup node + uses: actions/setup-node@v4 + with: + cache: npm + cache-dependency-path: ./package-lock.json + node-version: 22 + + - name: 📥 Install deps + run: npm install + + - name: 🔎 Type check + run: npm run typecheck --if-present + + vitest: + name: ⚡ Vitest + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: ⎔ Setup node + uses: actions/setup-node@v4 + with: + cache: npm + cache-dependency-path: ./package-lock.json + node-version: 22 + + - name: 📥 Install deps + run: npm install + + - name: ⚡ Run vitest + run: npm run test -- --coverage deploy: name: 🚀 Deploy runs-on: ubuntu-latest - # needs: [lint, typecheck, vitest] + needs: [lint, typecheck, vitest] steps: - name: ⬇️ Checkout repo uses: actions/checkout@v4 @@ -86,16 +86,16 @@ jobs: uses: superfly/flyctl-actions/setup-flyctl@1.5 - name: 🚀 Deploy Production - if: ${{ github.ref == 'refs/heads/brooks/fix-caching' }} + if: ${{ github.ref == 'refs/heads/main' }} run: flyctl deploy --remote-only --config ./fly.production.toml --build-arg COMMIT_SHA=${{ github.sha }} env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - # purge: - # name: 🧹 Purge CDN - # runs-on: ubuntu-latest - # needs: [deploy] - # steps: - # - name: 🧹 Purge All - # run: | - # curl -D - -X POST --location "https://api.fastly.com/service/${{ secrets.FASTLY_SERVICE_ID }}/purge_all" -H "Accept: application/json" -H "Fastly-Key: ${{ secrets.FASTLY_API_TOKEN }}" -H "fastly-soft-purge: 1" + purge: + name: 🧹 Purge CDN + runs-on: ubuntu-latest + needs: [deploy] + steps: + - name: 🧹 Purge All + run: | + curl -D - -X POST --location "https://api.fastly.com/service/${{ secrets.FASTLY_SERVICE_ID }}/purge_all" -H "Accept: application/json" -H "Fastly-Key: ${{ secrets.FASTLY_API_TOKEN }}" -H "fastly-soft-purge: 1"