Skip to content

Reload the page when a chunk fails to load - #88

Merged
lewisjared merged 5 commits into
mainfrom
fix/stale-chunk-reload
Sep 3, 2026
Merged

Reload the page when a chunk fails to load#88
lewisjared merged 5 commits into
mainfrom
fix/stale-chunk-reload

Conversation

@lewisjared

@lewisjared lewisjared commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Fixes the Failed to fetch dynamically imported module errors coming out of staging (REF-APP-BACKEND-1Y).

The static assets are baked into the container image, so a deploy replaces every hashed file. A tab left open across a deploy then asks for a chunk that no longer exists, the dynamic import rejects, and the route blows up in the error boundary.

  • Listens for Vite's vite:preloadError in main.tsx and reloads the page so the tab picks up the new build.
  • Rate limits the reload to once per 30 seconds, so a chunk that is genuinely missing cannot put the tab in a reload loop.

This only helps tabs that were already open. It does not keep old assets around, so a truly stale bookmark to an asset URL still 404s.

Summary by CodeRabbit

  • Bug Fixes
    • Automatically reloads the page when a required application resource fails to load after a deployment.
    • Prevents repeated reload loops by limiting automatic retries during persistent failures.
    • Ensures automatic recovery continues when browser storage access is blocked.
    • Prevents browsers from serving outdated application pages after a deployment by requiring HTML content to be revalidated.

A deploy replaces the hashed asset files, so a tab left open across a deploy asks for
chunks that no longer exist and the route fails to render. Listens for Vite's
`vite:preloadError` and reloads once to pick up the new build.
@netlify

netlify Bot commented Sep 3, 2026

Copy link
Copy Markdown

Deploy Preview for climate-ref ready!

Name Link
🔨 Latest commit e6fddf3
🔍 Latest deploy log https://app.netlify.com/projects/climate-ref/deploys/6a98efa3840527000837b02e
😎 Deploy Preview https://deploy-preview-88--climate-ref.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

Next included review available in 32 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: a16173ec-4d4b-472d-84f6-33bf4c475c64

📥 Commits

Reviewing files that changed from the base of the PR and between 834840b and e6fddf3.

📒 Files selected for processing (1)
  • frontend/src/main.tsx
📝 Walkthrough

Walkthrough

The frontend reloads after a Vite chunk preload error. Guarded sessionStorage access preserves the 30-second reload cooldown. The backend marks HTML responses as no-cache. A changelog entry documents the fix.

Changes

Chunk preload recovery

Layer / File(s) Summary
Preload error reload handling
frontend/src/main.tsx, changelog/88.fix.md
The vite:preloadError listener uses guarded sessionStorage helpers to limit reloads to one attempt per 30 seconds. The changelog records the recovery behaviour.
HTML response cache control
backend/src/ref_backend/builder.py
SPAStaticFiles.get_response adds Cache-Control: no-cache to HTML responses, including the index.html fallback response.

Merge Risk: 🟡 Moderate · up to 83484

The change recovers stale tabs after deployments by reloading on failed chunk preloads and revalidating HTML. However, users with blocked session storage can enter a reload loop if a chunk remains unavailable, so this should be fixed before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: reloading the page when a Vite chunk fails to load.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/stale-chunk-reload

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 9eb27dae-abed-4762-8e32-cce0413a3371

📥 Commits

Reviewing files that changed from the base of the PR and between 68dea67 and 4ee1949.

📒 Files selected for processing (2)
  • changelog/88.fix.md
  • frontend/src/main.tsx

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread changelog/88.fix.md Outdated
Comment thread frontend/src/main.tsx Outdated
Comment thread frontend/src/main.tsx
Guards the sessionStorage access, because a browser that blocks site data throws there and
would otherwise swallow the preload error without reloading. Sends `Cache-Control: no-cache`
with the SPA HTML, so the reload cannot be answered from cache with the old asset names.
@lewisjared

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: c1d288ad-7604-45a7-8f15-91d5169f91f7

📥 Commits

Reviewing files that changed from the base of the PR and between 4ee1949 and 834840b.

📒 Files selected for processing (3)
  • backend/src/ref_backend/builder.py
  • changelog/88.fix.md
  • frontend/src/main.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • changelog/88.fix.md

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread frontend/src/main.tsx
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Without storage there is no cooldown, so reloading on every preload error could loop.
Lets the error surface instead.
@lewisjared
lewisjared merged commit 3a82682 into main Sep 3, 2026
9 checks passed
@lewisjared
lewisjared deleted the fix/stale-chunk-reload branch September 3, 2026 05:01
@lewisjared

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Pull request is closed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

1 participant