Skip to content

Fix ingress prefix sticking in the importmap - #103

Closed
pudgeball wants to merge 15 commits into
timeframe:mainfrom
pudgeball:fix-ingress-importmap-cache
Closed

pudgeball wants to merge 15 commits into
timeframe:mainfrom
pudgeball:fix-ingress-importmap-cache

Conversation

@pudgeball

Copy link
Copy Markdown

importmap-rails caches the rendered importmap JSON and modulepreload paths on the process-wide Rails.application.importmap, keyed by a fixed key (:json / entry point). Those paths include relative_url_root, which we set per request from the ingress prefix, so whichever request rendered first after boot fixed the prefix for everyone:

  • Direct (IP:8099) first → the HA sidebar gets bare /assets/application-….js module URLs, which resolve against Home Assistant's own origin and 404, so Stimulus controllers never load (menus, alerts, collapses broken).
  • Ingress first → direct visitors get /api/hassio_ingress/<token>/assets/…, which 404 on the add-on's port.

This is why home_assistant_ingress_test.rb was order-dependent on main.

Fix: HomeAssistantIngress::ImportmapTags overrides javascript_importmap_tags / javascript_importmap_module_preload_tags to pass a cache_key that includes relative_url_root (an option importmap-rails provides for exactly this). It's prepended onto Importmap::ImportmapTagsHelper because adding it with helper lost to importmap's own helper depending on on_load order.

Tests: added a direct-then-ingress test (fails without the fix); ingress tests pass on 7+ seeds; full suite 914 runs, 0 failures. Bumps to 2.19.1 with a CHANGELOG entry.

🤖 Generated with Claude Code

pudgeball and others added 15 commits November 1, 2026 22:13
Home Assistant's calendar API now returns a `status` field on events
(e.g. Google Calendar's confirmed/tentative). calendar_events splatted
every field into DeviceEvent.new, so the unknown keyword raised
ArgumentError and the Events page, Status page and device renders all
returned 500.

Only pass through the keywords DeviceEvent#initialize accepts, and add
a regression test with a `status` field.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0157TCwfdp7oDPLpdzpdDM6q
* Identify fork in Home Assistant and bump to 2.15.1

repository.json and config.json still pointed at timeframe/ha-addon, so
Home Assistant showed this fork as Joel's repository. Rename it and point
its URLs here, and bump the version so Home Assistant offers the calendar
fix as an update instead of keeping the cached 2.15.0 build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0157TCwfdp7oDPLpdzpdDM6q

* Make the sidebar panel work through Home Assistant ingress

Home Assistant ingress serves the add-on from /api/hassio_ingress/<token>/
and passes that prefix in X-Ingress-Path. Rails ignored it, so styles,
icons, and the Events, Settings, and Status links pointed at Home
Assistant's root and 404'd.

Add middleware that turns a valid X-Ingress-Path into SCRIPT_NAME, set
relative_url_root per request so asset helpers carry the prefix, and
switch hard-coded root-relative URLs in the layouts, icon picker, CSS
fonts, and web manifest to helpers or relative paths. Direct requests on
port 8099 (TRMNL and other devices) are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Load icon and device fonts relative to their stylesheets

materialdesignicons.css and device.css pointed at /fonts/..., which skips
the Home Assistant ingress prefix, so the icon webfont 404'd in the
sidebar panel. Use paths relative to each stylesheet instead, which work
both through ingress and on direct port 8099 requests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Keep the 90-day uptime bar inside its card on narrow screens

Each of the 90 segments had a 2px minimum width plus 2px gaps, so the bar
couldn't shrink below ~358px and ran past the card edge in the Home
Assistant panel on phones. Let segments shrink to zero and use 1px gaps
below 640px.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Upstream fixed the same Home Assistant calendar `status` crash this fork
fixed in c793c63, more thoroughly (fetch_calendars now builds events from
an explicit field list, and calendar_events slices cached events too).
Conflicts in home_assistant_api.rb and its test were resolved by taking
upstream's version; its tests cover the fork's regression case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pages were capped at 375px. From md up the content widens to max-w-6xl,
the floating bottom nav becomes a top bar, device cards flow into a
2-3 column grid, and Events/Settings/Status/onboarding get sensible
desktop widths. Mobile layout is unchanged.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Home Assistant only offers an update when config.json's version changes.

Co-authored-by: Claude Opus 5.5 <[email protected]>
…16.1 (#5)

Through Home Assistant ingress, request.base_url is Home Assistant's
host, so the headless browser loaded /d/<id> on Home Assistant itself
and saved its 404 page as the screenshot. Use the add-on's own address
when the request has an ingress prefix.

The unchanged-content check also skipped forced refreshes, so the bad
image stuck until the calendar changed. Let the Regenerate button
always recapture.

Co-authored-by: Claude Opus 5.5 <[email protected]>
The forced-screenshot-through-ingress test sends Host: homeassistant.local
like Home Assistant's proxy does, but the test environment only allowed
www.example.com and 127.0.0.1, so Rails' host check answered 403 before the
request reached the controller. Production clears the host list, so only
the test was affected.

Co-authored-by: Claude Opus 5.5 <[email protected]>
* Add a Year view the TRMNL X can flip to with its button

A year-planner layout: the current month and the next 11 as rows, days
1-31 as columns, with multi-day events (and single-day events tagged
"timeframe-year") drawn as bars. Overlapping events stack up to three per
month, names shrink or move beside short bars, and today is a column of
polka dots with any events crossing it inverted.

- Home Assistant calendars are also fetched hourly for the next 12 months
  (a separate cache from the short-range fetch).
- "Year" is a new layout for the TRMNL X and reTerminal E1003.
- A "Year view on button press" setting adds it as a second page. A press
  wakes the device early, so a poll well before its scheduled refresh flips
  the page; a scheduled poll returns to the main layout. The current page
  and the Year page image live in the Rails cache, so no migration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Show the Year view's calendar fetch on the Status page

Lists, per calendar, how many events Home Assistant returned for the next
12 months, how many qualify for the Year view, and the latest one, to see
where events drop out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Draw each Year view month on its own and show layout errors

A layout error in one month stopped every later month from drawing their
events. Each month is now laid out separately, and a month that fails says
why on its row (and in the console).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Fetch the Year view calendars every 15 minutes

Hourly meant a newly added trip could take up to an hour to appear.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Bump to 2.17.0 for the Year view

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Regenerate passed the address the page was opened with to the headless
browser, which runs inside the add-on and can't always reach it (a different
port mapping, the host's LAN IP, a proxy). The add-on now always captures from
Puma at 127.0.0.1, via a Device.screenshot_host setting the engine falls back
from when unset. Bump to 2.17.1.

Co-authored-by: Claude Opus 5.5 <[email protected]>
TRMNL firmware 1.8.18+ sends an Update-Source header with its wake reason
(timer for a scheduled refresh, EXT0/button/... for a press or touch) and
special_function: rewind on a left tap. Use those instead of guessing from
the poll timing: a press flips between the main page and the Year page, a
left tap goes back, and a scheduled refresh, reboot or setup shows the main
page. Firmware without the header keeps the timing fallback.

Also:
- Name screen images <screen>-<id>-<unix time>, the format the firmware
  caches by, so the device keeps both pages.
- Show the main page if the Year page can't be captured.
- Log the wake reason, special_function and firmware version per check-in.
- Point the pairing message at the Timeframe dashboard, not timeframe.app.
- Bump to 2.17.2.

Co-authored-by: Claude Opus 5.5 <[email protected]>
* Fix Year view spans across months and the today marker

- Only single-day events get the date badge; a one-day slice of a longer
  event shows a continuation bar with its name beside it
- Bars carried into the next month keep their relative lane order
- Restore the highlight on today's date in the header row

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Draw today's date tab without a blend mode

The difference-blend layer rendered blank in the settings preview.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Bump version to 2.17.3

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
* Wake devices on the quarter hour

Devices slept a flat 15 minutes from whenever they checked in, so their
updates drifted around the clock. refresh_rate now wakes them a minute
after the next :00/:15/:30/:45 (at least 5 minutes away), and overnight at
the furthest quarter hour within 59 minutes, never past 05:01. The
pre-render job runs just after the quarter hour so the image the device
fetches shows that quarter hour's content.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Bump version to 2.18.0

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
* Add a Year screenshot tab with its own Regenerate button

With the Year page turned on, the settings page only showed and
regenerated the main page's screenshot, so a fresh Year capture had to
wait for the next scheduled refresh or a button press. The screenshot
action now takes page=1 to serve (and, with force, recapture) the Year
page, and the settings page shows a Year tab next to Screenshot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Show the Year screenshot tab as soon as the Year page is switched on

The tab was only rendered when the Year page was already on, so turning
the switch on needed a page reload to see it. It's now rendered (hidden)
whenever the device supports a Year page and shown or hidden when the
switch saves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Bump version to 2.19.0

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
importmap-rails memoizes the importmap JSON and modulepreload paths on the
process-wide map, so whichever request rendered first (ingress or direct)
fixed the prefix for every later one. Vary the cache key by
relative_url_root and add a direct-then-ingress test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@pudgeball

Copy link
Copy Markdown
Author

Opened against the wrong repository by mistake, sorry for the noise.

@pudgeball pudgeball closed this Nov 8, 2026
@pudgeball
pudgeball deleted the fix-ingress-importmap-cache branch November 8, 2026 23:14
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