Skip to content

fix(pwa): follow the phone's rotation lock in the installed app - #159

Merged
devswha merged 1 commit into
mainfrom
fix/pwa-rotation-lock
Sep 29, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/pwa-rotation-lock

Conversation

@devswha

@devswha devswha commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Change

Reported: the installed PWA on Android rotates sideways when the phone is tilted, even with auto-rotate locked.

Cause. The manifest set "orientation": "any". Chrome for Android maps any to SCREEN_ORIENTATION_FULL_SENSOR, which rotates by the sensor and ignores the system rotation lock. Chromium changed this to FULL_USER only in June 2026 (commit 73b80c267b, crbug 40880635), so current and older Chrome releases still behave this way. With no orientation, the lock type is DEFAULT, which maps to SCREEN_ORIENTATION_USER (or UNSPECIFIED on older Chrome). Both follow the phone's setting, and the app still rotates when auto-rotate is on.

Second cause, which kept the fix from reaching installs. sw.js served /manifest.webmanifest cache-first under a cache name that never changed. The browser rereads the manifest to update an installed app (WebAPK ORIENTATION_DIFFERS), so every install stayed on the manifest it first cached. server/static.ts already marks the manifest as must-revalidate; the service worker was overriding that.

  • public/manifest.webmanifest: orientation removed.
  • public/sw.js: the manifest is no longer cache-first, so it goes through the HTTP cache and revalidates. CACHE_NAME bumped to v3, so activation deletes the manifest already cached on devices.
  • src/pwa.test.ts: the manifest has no orientation, and the real sw.js fetch listener leaves the manifest alone while icons and hashed assets stay cache-first. Both tests fail against the previous files.

Existing installs pick this up the next time Chrome checks the installed app for updates (on launch, at most about once a day). Reinstalling applies it at once. iOS ignores the manifest orientation and already follows its rotation lock.

Test plan

  • bun run typecheck
  • bun run test:unit (441 pass)
  • src/pwa.test.ts fails on the old manifest and sw.js, passes on the new ones
  • bun run build: dist/manifest.webmanifest has no orientation; dist/sw.js is herdr-web-ui-v3-ram and has no cache-first manifest

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 9b990df2-559e-4e50-9c17-9ce58dbc0171

📥 Commits

Reviewing files that changed from the base of the PR and between 17e89f9 and 34efb41.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • public/manifest.webmanifest
  • public/sw.js
  • src/pwa.test.ts
💤 Files with no reviewable changes (1)
  • public/manifest.webmanifest

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Installed Android apps now follow the phone’s auto-rotate setting.
    • Manifest updates apply immediately after reinstalling, rather than being served from the service worker’s cache.

Walkthrough

The web manifest no longer sets an orientation preference. The service worker no longer serves it from cache-first paths. Tests cover both changes and verify that versioned icons and JavaScript assets still use the fetch listener.

Changes

PWA manifest behavior

Layer / File(s) Summary
Manifest and service worker behavior
public/manifest.webmanifest, public/sw.js
The manifest omits orientation. The service worker removes the manifest from CACHE_FIRST_PATHS and changes CACHE_NAME.
Behavior tests and changelog
src/pwa.test.ts, CHANGELOG.md
Tests check the manifest property and fetch-listener handling for the manifest, a versioned icon, and JavaScript. The changelog records the Android rotation and manifest update.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 34efb

Installed Android PWAs can generally follow the phone’s rotation setting, and the updated service worker no longer serves a cached manifest. No material merge risk is established.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 34efb

The change does not appear to expand access to private data or backend services. Replacing the installed app’s cache may, however, leave its offline fallback unavailable until a successful online visit replenishes it.

Retained concerns

  • Low · reliability · inferred: On upgrade, activation deletes the v2 cache before the v3 cache has a shell. An installed app that next navigates offline may therefore lose its existing fallback until an online navigation replenishes it.
Security review details

Security Blast Radius

  • inferred — The directly affected exposure is browser-side manifest delivery and cache state for installed clients, not a new backend request route or privilege.

Security Findings and Attack Paths

  • inferred — No new path from an intercepted request to sensitive backend traffic was identified in the examined worker: cross-origin requests and API or WebSocket routes remain excluded. This does not establish complete security coverage.

Trust Boundaries and Controls

  • observed — Same-origin GET gating remains the worker’s interception boundary; the manifest now falls through that handler to browser and HTTP-cache handling.

Resilience and Maintainability Implications

  • inferred — The cache rotation creates an offline-recovery handoff risk, but the inspected flow does not show a change to authorization or data isolation.

Hardening Proposals

  • proposed — Verify an upgrade followed by an offline launch and a rollback; if offline continuity is required, populate the replacement shell before removing the previous cache or retain the old shell through handoff.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary PWA behavior change: the installed app follows the phone's rotation lock.
Description check ✅ Passed The description explains the causes, implemented changes, update behavior, and validation results. It uses a "Test plan" heading instead of the template's "Validation" heading and does not include a s…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 …
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.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

@devswha
devswha merged commit fc4f8e0 into main Sep 29, 2026
3 checks passed
@devswha
devswha deleted the fix/pwa-rotation-lock branch September 29, 2026 13:11
devswha added a commit that referenced this pull request Sep 29, 2026
…an upgrade (#165)

## Change

Follow-up to #159. Reports kept coming after v0.3.32 that the installed
Android app still rotates with auto-rotate locked.

**Cause.** A service worker from 0.3.31 or older serves
`/manifest.webmanifest` cache-first. On the first launch after the
server upgrades, that old worker still controls the page, so the
document's manifest is the cached one with `orientation: "any"`. The
document keeps that manifest after the new worker activates. Chrome's
WebAPK update check (`WebApkUpdateManager`, at most once per 24 h per
launch) compares against this stale manifest, finds no change, and
records the check. The rotation fix then waits at least another day,
plus Chrome's charging + unmetered requirement for the re-mint.

- `index.html`: the manifest link is `/manifest.webmanifest?v=2`. No old
worker has that URL cached, so its cache-first path misses and fetches
the current manifest from the network. The server serves it by pathname
(`no-cache`, `application/manifest+json`). The installed app keeps its
identity: `webapk_update_data_fetcher.cc` accepts a new manifest URL
when the manifest `id` (`/`) matches.

Existing 0.3.32 installs that already launched once are unaffected by
this change and update on the next daily check. Reinstalling applies the
fix at once.

## Validation

- Chrome 151 + Playwright: installed with v0.3.31's `sw.js` and
manifest, then switched the server to the current files and relaunched.
`Page.getAppManifest` on the first launch after upgrade: `orientation:
"any"` with the plain link (no network request for the manifest), none
with `?v=2` (manifest fetched from the network). The second launch has
no orientation in both cases.
- `bun run build`: `dist/index.html` links `/manifest.webmanifest?v=2`.
- Real server: `GET /manifest.webmanifest?v=2` answers 200,
`application/manifest+json`, `Cache-Control: no-cache`, no
`orientation`.
- `HERDR_TEST_MODE=unit bun test ./src/pwa.test.ts`: 2 pass.
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