2026.11.1: offline flight logging fixed, inspections from logbook entries, life limits from installation, component inspections moved to inspection types

- Service worker keeps the Log Flight form when opened via Turbo, serves the offline page's script and icon, and treats 502/503/504 as offline; the offline page only links forms actually kept
- Serviced sub-components restart from the airframe time flown since the entry
- New logbook entries can complete inspections (recorded and linked to the entry)
- Components: replacement limit can count from installation (life limit)
- Component-level "Inspect every" / "Inspection critical" removed; a migration converts any unlinked settings into inspection types with a first record; component page lists its inspections

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-12 07:30:59 -05:00
1 parent 7552e4a8a3
commit 352a38c7fb
28 files changed
+289 -69

No files matched your search

+4 -4
View File
@@ -23,6 +23,8 @@ class ComponentsController < ApplicationController
def show
@squawks = @component.squawks.by_priority.with_attached_attachments
ids = @component.inspection_type_ids
@inspection_rows = Compliance.inspection_rows(@aircraft).select { ids.include?(_1.type.id) }
end
def new
@@ -76,10 +78,8 @@ class ComponentsController < ApplicationController
params.require(:component).permit(
:component_type_id, :parent_component_id, :manufacturer, :model, :serial_number,
:install_location, :notes, :status, :date_in_service, :hours_in_service,
:hours_since_overhaul, :overhaul_date, :overhaul_kind, :tbo_hours, :tbo_days, :inspection_hours,
:inspection_days, :replacement_hours, :replacement_days, :replacement_every, :replacement_unit, :tbo_every, :tbo_unit,
:inspection_every, :inspection_unit, :tbo_critical, :on_condition,
:inspection_critical, :replacement_critical, :expires_on
:hours_since_overhaul, :overhaul_date, :overhaul_kind, :tbo_hours, :tbo_days, :replacement_hours, :replacement_days, :replacement_every, :replacement_unit, :tbo_every, :tbo_unit,
:tbo_critical, :on_condition, :replacement_critical, :replacement_from_install, :expires_on
).tap do |p|
# Owners can create a component type inline instead of asking an admin.
if (name = params[:new_component_type].to_s.strip).present?
@@ -11,6 +11,11 @@ class InspectionTypesController < ApplicationController
@inspection_type.name = "ICA: #{@major_record.title}".first(120)
@applies_to_airframe = @major_record.component.nil?
@inspection_type.components = [ @major_record.component ] if @major_record.component
elsif (component = @aircraft.components.find_by(id: params[:component_id]))
# From a component's page: applies to that part, e.g. "Magneto 500-hour inspection".
@inspection_type.name = "#{component} inspection"
@inspection_type.components = [ component ]
@applies_to_airframe = false
end
end
+14 -1
View File
@@ -38,6 +38,7 @@ class LogbookEntriesController < ApplicationController
if @entry.save
log_event("logbook", "Logbook entry #{@entry.supersedes ? 'correction ' : ''}added (#{@entry.date})")
record_parts_service
record_inspections
redirect_to aircraft_logbook_entry_path(@aircraft, @entry),
notice: @entry.supersedes ? "Correction saved. Sign it to supersede the original entry." : "Logbook entry added."
else
@@ -92,15 +93,27 @@ class LogbookEntriesController < ApplicationController
# Sub-components marked "Serviced" or "Replaced" on a new entry: recorded on
# the Components tab too, dated to the entry.
def record_parts_service
flown = (@aircraft.current_hours - @entry.aircraft_hours_at_entry if @entry.aircraft_hours_at_entry)
parts_params.each do |id, p|
next unless p["include"] == "1" && %w[serviced replaced].include?(p["service"])
part = @entry.parts.find { _1.component_id == id.to_i } or next
component = part.component
component.service_from_entry!(date: @entry.date, hours_at_entry: part.hours_at_entry, replaced: p["service"] == "replaced")
component.service_from_entry!(date: @entry.date, hours_at_entry: part.hours_at_entry, flown_since: flown, replaced: p["service"] == "replaced")
log_event("component", "#{p['service'] == 'replaced' ? 'Replaced' : 'Serviced'}: #{component} (logbook entry #{@entry.date})")
end
end
# Inspections ticked on a new entry (e.g. Oil Change): done at the entry's
# date and airframe time, linked to it.
def record_inspections
ids = Array(params.dig(:logbook_entry, :inspection_type_ids)).compact_blank
@aircraft.applicable_inspection_types.where(id: ids).find_each do |type|
@aircraft.inspection_records.create!(inspection_type: type, logbook_entry: @entry, date: @entry.date,
aircraft_hours: @entry.aircraft_hours_at_entry)
log_event("inspection", "Inspection completed: #{type.name} (logbook entry #{@entry.date})")
end
end
# Sub-components ticked on the form: { component_id => { include, hours, since, service } }.
def parts_params
params.fetch(:logbook_entry, {}).permit(parts: {})[:parts]&.to_h || {}
@@ -35,6 +35,14 @@ export default class extends Controller {
if (this.pending) await this.save(this.pending)
}
// A proxy answered because the app is unreachable (502/503/504): keep the
// flight instead of showing the proxy's error page.
async gatewayFailed(event) {
if (![ 502, 503, 504 ].includes(event.detail.fetchResponse.statusCode) || !this.pending) return
event.preventDefault()
await this.save(this.pending)
}
async save(fields) {
const item = { id: this.keyTarget.value, url: this.element.action, tail: this.tailValue, savedAt: new Date().toISOString(), fields }
try {
@@ -46,6 +46,7 @@ export default class extends Controller {
try {
response = await fetch(item.url, { method: "POST", body, credentials: "same-origin", headers: { Accept: "text/html" } })
} catch (_) { return "offline" }
if ([ 502, 503, 504 ].includes(response.status)) return "offline"
if (response.url.includes("/session/new")) return "signin"
if (response.ok) return "sent"
const html = await response.text()
+20 -7
View File
@@ -8,7 +8,6 @@ class Component < ApplicationRecord
calendar_interval :replacement, days: :replacement_days, months: :replacement_months
calendar_interval :tbo, days: :tbo_days, months: :tbo_months
calendar_interval :inspection, days: :inspection_days, months: :inspection_months
belongs_to :aircraft, optional: true
belongs_to :parent_component, class_name: "Component", optional: true
@@ -63,15 +62,21 @@ class Component < ApplicationRecord
tbo_hours - hours_since_overhaul if tbo_hours
end
# The hours the replacement limit counts: since installed for a life-limited
# part that's serviced and reused, else since its last service.
def replacement_hours_used = replacement_from_install? ? hours_in_service : hours_since_overhaul
def replacement_counted_from = replacement_from_install? ? date_in_service : overhaul_date
def hours_to_replacement
replacement_hours - hours_since_overhaul if replacement_hours
replacement_hours - replacement_hours_used if replacement_hours
end
# Past the date marked on the part (it may be used through that date).
def expired?(today = Date.current) = expires_on.present? && today > expires_on
def next_replacement_date
replacement_after(overhaul_date)
replacement_after(replacement_counted_from)
end
# :overdue / :due_soon / :ok / nil (not tracked) for display on the components tab.
@@ -96,10 +101,18 @@ class Component < ApplicationRecord
# Service reset: always zeroes time since overhaul; optionally the whole
# in-service clock when the part was physically replaced.
# Serviced (or replaced) as recorded in a logbook entry: dated to the entry,
# with the hours it has run since then (its total time now less its total
# time at the entry) as the new time since service.
def service_from_entry!(date:, hours_at_entry:, replaced: false)
since = hours_at_entry ? [ hours_in_service.to_d - hours_at_entry.to_d, 0 ].max : 0
# with the hours it has run since then as the new time since service. That's
# the airframe time flown since the entry when known (the part's own total
# at the entry is often typed as 0 for new oil, which would keep the old
# hours), else its total time now less its total time at the entry.
def service_from_entry!(date:, hours_at_entry:, flown_since: nil, replaced: false)
since =
if flown_since then flown_since.to_d
elsif hours_at_entry then hours_in_service.to_d - hours_at_entry.to_d
else 0
end
since = [ since, 0 ].max
since = [ since, hours_in_service.to_d ].min unless replaced # can't have run longer since service than in total
attrs = { hours_since_overhaul: since, overhaul_date: date }
attrs.merge!(hours_in_service: since, date_in_service: date) if replaced
update!(attrs)
+4 -3
View File
@@ -145,10 +145,11 @@ module AircraftArchive
manufacturer: c.manufacturer, model: c.model, serial_number: c.serial_number, install_location: c.install_location,
expires_on: c.expires_on&.iso8601, notes: c.notes, status: c.status, date_in_service: c.date_in_service&.iso8601, hours_in_service: dec(c.hours_in_service),
hours_since_overhaul: dec(c.hours_since_overhaul), overhaul_date: c.overhaul_date&.iso8601, tbo_hours: c.tbo_hours,
tbo_days: c.tbo_days, inspection_hours: c.inspection_hours, inspection_days: c.inspection_days,
tbo_days: c.tbo_days,
replacement_hours: c.replacement_hours, replacement_days: c.replacement_days,
replacement_months: c.replacement_months, tbo_months: c.tbo_months, inspection_months: c.inspection_months, tbo_critical: c.tbo_critical,
on_condition: c.on_condition, inspection_critical: c.inspection_critical, replacement_critical: c.replacement_critical }
replacement_months: c.replacement_months, tbo_months: c.tbo_months, tbo_critical: c.tbo_critical,
on_condition: c.on_condition, replacement_critical: c.replacement_critical,
replacement_from_install: c.replacement_from_install }
end
def logbook_hash(e)
+3 -3
View File
@@ -215,9 +215,9 @@ module AircraftArchive
status: Component::STATUSES.key?(data["status"]) ? data["status"] : "SPARE",
date_in_service: date(data["date_in_service"]) || Date.new(1900, 1, 1), hours_in_service: num(data["hours_in_service"]) || 0,
hours_since_overhaul: num(data["hours_since_overhaul"]) || 0, overhaul_date: date(data["overhaul_date"]),
**data.slice(*%w[tbo_hours tbo_days inspection_hours inspection_days replacement_hours replacement_days
tbo_months inspection_months replacement_months]).symbolize_keys,
**data.slice(*%w[tbo_critical on_condition inspection_critical replacement_critical]).transform_values { _1 == true }.symbolize_keys
**data.slice(*%w[tbo_hours tbo_days replacement_hours replacement_days
tbo_months replacement_months]).symbolize_keys,
**data.slice(*%w[tbo_critical on_condition replacement_critical replacement_from_install]).transform_values { _1 == true }.symbolize_keys
)
c.save!(validate: false)
@map[:component][data["id"].to_s] = c.id
+6 -5
View File
@@ -146,19 +146,20 @@ class Airworthiness
desc = ""
if c.replacement_critical? && c.replacement_hours
if c.hours_since_overhaul >= c.replacement_hours
used = c.replacement_hours_used
if used >= c.replacement_hours
overdue = true
desc = "Replace every #{c.replacement_hours} hrs. Current: #{c.hours_since_overhaul} hrs."
elsif c.hours_since_overhaul + HOURS_WARNING >= c.replacement_hours
desc = "Replace every #{c.replacement_hours} hrs. Current: #{used} hrs#{' since installed' if c.replacement_from_install?}."
elsif used + HOURS_WARNING >= c.replacement_hours
approaching = true
desc = "Replace in #{c.replacement_hours - c.hours_since_overhaul} hrs."
desc = "Replace in #{c.replacement_hours - used} hrs."
end
end
if c.replacement_critical? && (due = c.next_replacement_date)
if @today >= due
overdue = true
desc = "Replace every #{c.replacement_interval_label}. Last serviced #{c.overhaul_date}."
desc = "Replace every #{c.replacement_interval_label}. #{c.replacement_from_install? ? 'Installed' : 'Last serviced'} #{c.replacement_counted_from}."
elsif @today + DAYS_WARNING >= due
approaching = true
desc = "Replace in #{(due - @today).to_i} days."
+2 -8
View File
@@ -57,23 +57,17 @@ class DueList
end
end
# A component's own "Inspect every" counts from its last service; when an
# inspection type covers the component, that inspection (tracked from its
# records, under inspections) governs instead.
def components
@aircraft.components.in_use.includes(:component_type, :inspection_types).flat_map do |c|
@aircraft.components.in_use.includes(:component_type).flat_map do |c|
label = "#{c} #{c.model}".strip
path = @urls.aircraft_component_path(@aircraft, c)
since_service = c.hours_since_overhaul.to_d
[
(item("replace-#{c.id}", "Replace #{label}", "component", path, date: c.next_replacement_date,
hours_left: c.replacement_hours && c.replacement_hours - since_service) if c.replacement_hours || c.replacement_calendar?),
hours_left: c.hours_to_replacement) if c.replacement_hours || c.replacement_calendar?),
(item("tbo-#{c.id}", "#{label} reaches TBO", "component", path,
date: c.tbo_after(c.overhaul_date),
hours_left: c.tbo_hours && c.tbo_hours - since_service) if (c.tbo_hours || c.tbo_calendar?) && !c.on_condition?),
(item("inspect-#{c.id}", "Inspect #{label}", "component", path,
date: c.inspection_after(c.overhaul_date),
hours_left: c.inspection_hours && c.inspection_hours - since_service) if (c.inspection_hours || c.inspection_calendar?) && c.inspection_types.empty?),
(item("expires-#{c.id}", "#{label} expires", "component", path, date: c.expires_on) if c.expires_on)
]
end
+4 -4
View File
@@ -29,6 +29,9 @@
<legend class="mb-2 text-sm font-semibold text-slate-900">Limits</legend>
<%= f.field :replacement_hours, as: :number, label: "Replace every (hrs)" %>
<%= f.interval :replacement, label: "Replace every" %>
<%= f.field :replacement_from_install, as: :select, label: "Replacement counts from",
collection: [ [ "Last service", false ], [ "Installation (life limit)", true ] ],
hint: "Installation: for a part that's cleaned and reused but has a life limit (e.g. a reusable oil filter); only Replaced restarts it." %>
<%= f.field :replacement_critical, as: :checkbox, label: "Replacement critical", hint: "Overdue replacement or expiry grounds the aircraft (oil, filters, ELT battery…)." %>
<%= f.field :expires_on, as: :date, label: "Expires on",
hint: "The date marked on the part, e.g. an ELT battery's replacement date (14 CFR 91.207(c): also replace it after 1 hour of cumulative use)." %>
@@ -40,10 +43,7 @@
<%= f.field :on_condition, as: :checkbox, label: "On condition (Part 91)",
hint: "Run past TBO based on condition: TBO is shown for reference, never as a limit (this overrides the hard limit)." %>
</div>
<%= f.field :inspection_hours, as: :number, label: "Inspect every (hrs)" %>
<%= f.interval :inspection, label: "Inspect every",
hint: "Counted from the component's last service. If an inspection (Inspections tab) applies to this component, that inspection and its records govern and these are ignored." %>
<%= f.field :inspection_critical, as: :checkbox, label: "Inspection critical" %>
<p class="hint sm:col-span-3">Recurring inspections of this part (e.g. a 500-hour magneto inspection) are set up on the Inspections tab and applied to it.</p>
</fieldset>
<%= f.field :notes, as: :textarea, rows: 3 %>
+1 -1
View File
@@ -32,7 +32,7 @@
<td class="text-right tabular-nums"><%= hours(c.hours_since_overhaul) %></td>
<td class="text-xs text-slate-600">
<% if c.replacement_critical? && (c.replacement_hours || c.replacement_calendar?) %>
Replace: <%= [c.replacement_hours && "#{c.replacement_hours} h", c.replacement_interval_label].compact.join(" / ") %><br>
Replace: <%= [c.replacement_hours && "#{c.replacement_hours} h", c.replacement_interval_label].compact.join(" / ") %><%= " since installed" if c.replacement_from_install? %><br>
<% end %>
<% if c.tbo_critical? && c.tbo_hours %>TBO: <%= c.tbo_hours %> h<%= " (on condition)" if c.on_condition? %><br><% end %>
<% if c.expires_on %>Expires: <%= fmt_date(c.expires_on) %><% end %>
+29 -2
View File
@@ -24,12 +24,12 @@
<dt class="text-slate-500">Since OH / service</dt><dd><%= hours(@component.hours_since_overhaul) %></dd>
<dt class="text-slate-500">TBO</dt><dd><%= @component.tbo_hours ? "#{@component.tbo_hours} h (#{hours(@component.hours_to_tbo)} remaining)" : "—" %></dd>
<dt class="text-slate-500">Replacement</dt><dd>
<%= [@component.replacement_hours && "#{@component.replacement_hours} h", @component.replacement_interval_label].compact.join(" / ").presence || "—" %>
<%= [@component.replacement_hours && "#{@component.replacement_hours} h", @component.replacement_interval_label].compact.join(" / ").presence&.then { @component.replacement_from_install? ? "#{_1} since installed" : _1 } || "—" %>
<% if (d = @component.next_replacement_date) %><div class="text-xs text-slate-500">Next by <%= fmt_date(d) %></div><% end %>
</dd>
<dt class="text-slate-500">Flags</dt>
<dd class="col-span-3 flex flex-wrap gap-1">
<% { tbo_critical: "TBO critical", replacement_critical: "Replacement critical", inspection_critical: "Inspection critical", on_condition: "On condition" }.each do |flag, label| %>
<% { tbo_critical: "TBO critical", replacement_critical: "Replacement critical", on_condition: "On condition" }.each do |flag, label| %>
<% if @component.public_send("#{flag}?") %><span class="badge-blue"><%= label %></span><% end %>
<% end %>
</dd>
@@ -53,6 +53,33 @@
<% end %>
</div>
<% if @inspection_rows.any? || owner? %>
<section class="card mt-5" id="inspections">
<div class="card-header">
<h2 class="card-title">Inspections of this component</h2>
<% if owner? %><%= link_to "+ Inspection", new_aircraft_inspection_type_path(@aircraft, component_id: @component.id), class: "btn-secondary btn-sm" %><% end %>
</div>
<% if @inspection_rows.any? %>
<table class="table">
<thead><tr><th>Inspection</th><th>Interval</th><th>Last done</th><th>Next due</th><th>Status</th></tr></thead>
<tbody>
<% @inspection_rows.each do |row| %>
<tr>
<td class="font-medium"><%= row.type.name %><%= tag.span(" advisory", class: "text-xs text-slate-500") if row.type.advisory? %></td>
<td class="text-xs"><%= row.type.interval_description %></td>
<td class="text-xs"><%= row.latest ? "#{fmt_date(row.latest.date)} @ #{hours(row.latest.hours_at_inspection)} h" : "—" %></td>
<td class="text-xs"><%= [row.next_due_date&.to_s, row.next_due_hours && "#{hours(row.next_due_hours)} h"].compact.join(" / ").presence || "—" %></td>
<td><%= compliance_badge(row.status) %></td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="card-body text-sm text-slate-500">None. Add one for a recurring inspection of this part (e.g. a 500-hour magneto inspection); it's tracked on the Inspections tab and can be completed from a logbook entry.</p>
<% end %>
</section>
<% end %>
<% if @squawks.any? %>
<section class="card mt-5">
<div class="card-header"><h2 class="card-title">Squawks on this component</h2></div>
+1 -1
View File
@@ -2,7 +2,7 @@
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<%= form_with model: [@aircraft, @flight_log], class: "card card-body space-y-5 max-w-3xl",
data: { controller: "offline-flight", offline_flight_tail_value: @aircraft.tail_number,
action: "submit->offline-flight#submit turbo:submit-start->offline-flight#remember turbo:fetch-request-error->offline-flight#networkFailed" } do |f| %>
action: "submit->offline-flight#submit turbo:submit-start->offline-flight#remember turbo:fetch-request-error->offline-flight#networkFailed turbo:before-fetch-response->offline-flight#gatewayFailed" } do |f| %>
<%= f.hidden_field :client_key, data: { offline_flight_target: "key" } %>
<div class="hidden rounded-md bg-sky-50 px-3 py-2 text-sm text-sky-900 ring-1 ring-sky-200" data-offline-flight-target="notice" role="status"></div>
<%= f.errors_summary %>
+17
View File
@@ -33,6 +33,23 @@
<%= f.field :text, as: :textarea, label: "Entry text", rows: 8, data: { entry_template_target: "text" } %>
<p class="hint !mt-1">A maintenance entry needs a description of the work, the date, and the name, signature, certificate number and kind of certificate of whoever approved the return to service (14 CFR 43.9). An inspection entry also needs the type and extent of the inspection, the aircraft's time in service, and the result (43.11).</p>
<%= render "shared/sign_as" %>
<% if entry.new_record? && (types = aircraft.applicable_inspection_types.order(:name)).any? %>
<%# Recurring items this work completes (e.g. an oil change): recorded on the Inspections tab, dated to this entry. %>
<% ticked = Array(params.dig(:logbook_entry, :inspection_type_ids)).map(&:to_s) %>
<fieldset>
<legend class="label">Inspections completed</legend>
<div class="grid gap-x-4 gap-y-1 sm:grid-cols-3">
<% types.each do |t| %>
<label class="flex items-center gap-2 text-sm">
<%= check_box_tag "logbook_entry[inspection_type_ids][]", t.id, ticked.include?(t.id.to_s), id: "inspection_type_#{t.id}",
class: "h-4 w-4 shrink-0 rounded border-slate-300" %>
<span><%= t.name %></span>
</label>
<% end %>
</div>
<p class="hint">Ticked ones are recorded as done on the Inspections tab, at this entry's date and airframe time, linked to this entry.</p>
</fieldset>
<% end %>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :signoff_person, label: "Signed off by", placeholder: "Name", data: { signer_target: "name" } %>
<%= f.field :signoff_certificate_type, as: :select, label: "Kind of certificate", include_blank: "—",
+29 -6
View File
@@ -2,12 +2,15 @@
// static files (the offline page, icons, fingerprinted /assets/) and, so a
// flight can be logged without signal, the Log Flight forms you've opened
// (tail number and meter readings only). Other aircraft pages are never cached.
const VERSION = "v2"
const VERSION = "v5"
const FORM_CACHE = "sam-flight-forms"
const FLIGHT_FORM = /^\/aircraft\/\d+\/flight_logs\/new$/
const SHELL_CACHE = `sam-shell-${VERSION}`
const ASSET_CACHE = "sam-assets"
const MAX_ASSETS = 80
// A proxy in front of the app (Traefik, Authentik) answers these when the app
// itself can't be reached: treat them like no connection.
const UNREACHABLE = [ 502, 503, 504 ]
const SHELL = [ "/offline.html", "/offline.js", "/icon.svg", "/icon-192.png" ]
self.addEventListener("install", (event) => {
@@ -28,11 +31,20 @@ self.addEventListener("fetch", (event) => {
const url = new URL(request.url)
if (url.origin !== self.location.origin) return
if (request.mode === "navigate" && FLIGHT_FORM.test(url.pathname)) {
// Turbo opens pages with fetch(), not a navigation, so match those too or
// the form is never kept when reached by tapping "Log Flight".
const wantsHtml = request.mode === "navigate" || (request.headers.get("Accept") || "").includes("text/html")
if (wantsHtml && FLIGHT_FORM.test(url.pathname)) {
event.respondWith(flightForm(request))
} else if (request.mode === "navigate") {
// Always go to the network for pages; show the offline page if it's unreachable.
event.respondWith(fetch(request).catch(() => caches.match("/offline.html")))
event.respondWith(fetch(request)
.then((response) => UNREACHABLE.includes(response.status) ? caches.match("/offline.html") : response)
.catch(() => caches.match("/offline.html")))
} else if (SHELL.includes(url.pathname)) {
// The offline page's own script and icon: fresh when online, kept copy when not.
event.respondWith(fetch(request).then((r) => r.ok ? r : caches.match(url.pathname).then((hit) => hit || r))
.catch(() => caches.match(url.pathname)))
} else if (url.pathname.startsWith("/assets/")) {
event.respondWith(cachedAsset(request))
}
@@ -61,11 +73,22 @@ async function trim(cache) {
// the kept copy when there isn't.
async function flightForm(request) {
const cache = await caches.open(FORM_CACHE)
const key = request.url.split("?")[0]
try {
const response = await fetch(request)
if (response.ok && !response.redirected) await cache.put(request.url.split("?")[0], response.clone())
if (UNREACHABLE.includes(response.status)) {
const kept = await cache.match(key)
if (kept) return kept
return request.mode === "navigate" ? caches.match("/offline.html") : response
}
const html = (response.headers.get("Content-Type") || "").includes("text/html")
if (response.ok && !response.redirected && html) await cache.put(key, response.clone())
return response
} catch (_) {
return (await cache.match(request.url.split("?")[0])) || caches.match("/offline.html")
} catch (error) {
const kept = await cache.match(key)
if (kept) return kept
// A Turbo fetch gets the error, so Turbo falls back to a full page load.
if (request.mode !== "navigate") throw error
return caches.match("/offline.html")
}
}