Skip to content

Commit 08cfb85

Browse files
authored
Fix front end chunking and add workflow dispatch to deploy previous release to prod (#646)
1 parent 3981424 commit 08cfb85

2 files changed

Lines changed: 45 additions & 8 deletions

File tree

.github/workflows/deploy-production.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ on:
66
release:
77
types:
88
- published
9+
workflow_dispatch:
10+
inputs:
11+
tag:
12+
description: "Published release tag to deploy, e.g. v1.2.3. Use this to roll back by redeploying a previous release."
13+
required: true
14+
type: string
915

1016
jobs:
1117
deploy:
@@ -49,7 +55,29 @@ jobs:
4955
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
5056
GRAFANA_ADMIN_PASSWORD: ${{ secrets.GRAFANA_ADMIN_PASSWORD }}
5157
steps:
58+
- name: Resolve and validate release tag
59+
id: tag
60+
env:
61+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: |
63+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
64+
TAG="${{ inputs.tag }}"
65+
else
66+
TAG="${{ github.event.release.tag_name }}"
67+
fi
68+
echo "Validating release tag: $TAG"
69+
status=$(curl -sS -o /dev/null -w '%{http_code}' \
70+
-H "Authorization: Bearer $GH_TOKEN" \
71+
-H "Accept: application/vnd.github+json" \
72+
"https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG")
73+
if [ "$status" != "200" ]; then
74+
echo "::error::'$TAG' is not a published release (HTTP $status); only tagged releases can be deployed."
75+
exit 1
76+
fi
77+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
5278
- name: Checkout
5379
uses: actions/checkout@v7
80+
with:
81+
ref: ${{ steps.tag.outputs.tag }}
5482
- run: docker compose -f docker-compose.yml --project-name ${{ vars.STACK_NAME }} build
5583
- run: docker compose -f docker-compose.yml --project-name ${{ vars.STACK_NAME }} up -d

frontend/vite.config.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ export default defineConfig({
3131
return "vendor-plotly"
3232
}
3333

34-
// Mermaid and its rendering graph (d3, dagre, khroma, cytoscape,
35-
// elkjs) must stay in ONE chunk. Splitting this tightly-coupled,
36-
// circular dependency graph across chunks reorders module init and
37-
// triggers a "Cannot access 'x' before initialization" TDZ error in
38-
// mermaid's theme code on load.
34+
// Let mermaid and its rendering graph (d3, dagre, khroma, cytoscape,
35+
// elkjs, lodash-es) auto-chunk. Mermaid lazy-loads each diagram type
36+
// via internal dynamic import(); forcing the graph into one manual
37+
// chunk collapses those async boundaries into synchronous circular
38+
// references, which throw "Cannot access 'x' before initialization"
39+
// TDZ errors during theme setup and rendering. Returning undefined
40+
// lets Rollup preserve mermaid's internal async chunk boundaries.
3941
if (
4042
id.includes("mermaid") ||
4143
id.includes("/d3-") ||
@@ -44,17 +46,24 @@ export default defineConfig({
4446
id.includes("khroma") ||
4547
id.includes("cytoscape") ||
4648
id.includes("elkjs") ||
47-
id.includes("non-layered-tidy-tree-layout")
49+
id.includes("non-layered-tidy-tree-layout") ||
50+
id.includes("lodash-es")
4851
) {
49-
return "vendor-mermaid"
52+
return undefined
5053
}
5154

55+
// react-ipynb-renderer, mathjax and katex form an interdependent
56+
// graph that also cross-imports the markdown/syntax chunks (and katex
57+
// is pulled in by mermaid). Force-merging them into one chunk creates
58+
// circular chunk dependencies whose const/class bindings evaluate out
59+
// of order, throwing "Cannot access 'x' before initialization" TDZ
60+
// errors on load. Let Rollup auto-chunk this graph instead.
5261
if (
5362
id.includes("react-ipynb-renderer") ||
5463
id.includes("mathjax") ||
5564
id.includes("katex")
5665
) {
57-
return "vendor-notebooks"
66+
return undefined
5867
}
5968

6069
if (

0 commit comments

Comments
 (0)