apps/web preview overwrites newly built dist/index.html with stale dist/index.html.bak across builds

Đang mở Phù hợp với người mới
#1,938 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, typescript, vite
Lĩnh vực
build-system, tooling

Hướng nghiên cứu

Bắt đầu với apps/web/package.json:8 (build) và apps/web/package.json:11 (preview), sau đó là apps/web/vite.config.ts:43 nơi emptyOutDir: false được đặt; so sánh các script build của apps/api/package.json và apps/gateway/package.json để tìm mẫu dọn dẹp. Lưu ý rằng turbo.json:11 cache dist/**, đó là lý do file .bak cũ vẫn tồn tại. Hoàn tất khi lần chạy pnpm test:e2e thứ hai sau một thay đổi mã phục vụ các chunk đã băm mới được phát ra, được xác minh bằng cách kiểm tra các thẻ <script> trong apps/web/dist/index.html.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Area: Infrastructure Area: Web Bug Difficulty: Low Priority: Medium

apps/web/vite.config.ts:43 sets build.emptyOutDir: false, and apps/web/package.json:8 ("build": "tsc && NODE_ENV=production NODE_OPTIONS='--import=tsx' pnpm exec vite build") does not remove dist before building.

When pnpm test:e2e starts apps/web's preview script (apps/web/package.json:11):

env-cmd -f ../../.env -- pnpm exec import-meta-env -x .env.public -p dist/index.html && NODE_OPTIONS='--import=tsx' env-cmd -f ../../.env pnpm exec vite preview

@import-meta-env/cli saves a backup of dist/index.html to dist/index.html.bak on the first run and, whenever dist/index.html.bak already exists, reads dist/index.html.bak as its template and overwrites dist/index.html with it.

Because vite build has emptyOutDir: false:

  1. Subsequent pnpm build runs write a new dist/index.html and new content-hashed dist/assets/*.js chunks, while leaving the old dist/index.html.bak and old dist/assets/*.js files in apps/web/dist/.
  2. Turbo caches dist/** (turbo.json:11), including the stale dist/index.html.bak.
  3. On the next pnpm test:e2e run, import-meta-env overwrites the newly built dist/index.html with the stale dist/index.html.bak, so vite preview serves the old hashed JS chunks from an earlier build or branch instead of the current apps/web code.
Reproduction
  1. Run pnpm test:e2e (which creates apps/web/dist/index.html.bak via pnpm preview).
  2. Change code in apps/web (or switch branches) and run pnpm test:e2e again without rm -rf apps/web/dist.
  3. Inspect apps/web/dist/index.html after pnpm preview starts: its <script> and <link rel="modulepreload"> tags match apps/web/dist/index.html.bak from step 1 rather than the newly emitted chunks from step 2.
Possible fix

Clean dist before vite build in apps/web/package.json (matching apps/api/package.json and apps/gateway/package.json, or enable emptyOutDir: true if runtime plugin ordering allows it) or remove dist/index.html.bak during apps/web build.

Ngôn ngữ chính
TypeScript
Star
119
Fork
19
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
60

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của DouglasNeuroInformatics/OpenDataCapture

Tất cả issue của DouglasNeuroInformatics/OpenDataCapture

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.