From ff4b4dbe7681d92136d90c167bf2b994ecb4cdb3 Mon Sep 17 00:00:00 2001 From: sherwinski Date: Thu, 28 May 2026 14:11:35 -0700 Subject: [PATCH 01/10] chore(preview): [SDK-4336] add iOS PWA repro sandbox (revert before merge) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the reproducible demo we used to verify the SDK-4336 fix on a real iOS Safari PWA. Lets a reviewer reproduce the original 30-minute init hang on `main` and confirm the fix branch resolves it. What's included: - `preview/pageA.html`, `preview/pageB.html` — minimal two-page sandbox with a Register button on Page A, designed to exercise the navigation-after-push-subscription flow described in the ticket. Page A persists `app_id` to `localStorage` so subsequent in-page navigations don't lose it (the in-page links don't carry the query string, which would otherwise produce `InvalidAppIdError`). - Both pages set `apple-mobile-web-app-capable` so they install as a standalone PWA when added to the Home Screen. - `preview/OneSignalSDKWorker.js` and `preview/push/onesignal/OneSignalSDKWorker.js` now `importScripts` from `self.location.origin` instead of a hardcoded `https://localhost:4001`, so the worker resolves correctly when the dev server is exposed via an ngrok / Cloudflare tunnel for on-device testing. - `preview/vite.config.ts` disables HMR (the WebSocket can't reach a device through a tunnel and floods the console with unhandled-rejection spam from `ws.send`), strips Vite's auto-injected `/@vite/client` from HTML responses for the same reason, and sends `Cache-Control: no-store` for SDK assets and HTML so iOS Safari / PWA doesn't pin a stale build during a debug session. This commit is intentionally **not** part of the SDK fix; it should be reverted before merging the PR. Kept in branch history so we can re-introduce it if SDK-4336 surfaces again. --- preview/OneSignalSDKWorker.js | 7 +- preview/pageA.html | 76 ++++++++++++++++++++ preview/pageB.html | 23 ++++++ preview/push/onesignal/OneSignalSDKWorker.js | 2 +- preview/vite.config.ts | 39 ++++++++++ 5 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 preview/pageA.html create mode 100644 preview/pageB.html diff --git a/preview/OneSignalSDKWorker.js b/preview/OneSignalSDKWorker.js index 0e7564295..964788d31 100644 --- a/preview/OneSignalSDKWorker.js +++ b/preview/OneSignalSDKWorker.js @@ -1,4 +1,9 @@ -importScripts('https://localhost:4001/sdks/web/v16/Dev-OneSignalSDK.sw.js'); +// Use self.location.origin so the worker imports from whichever origin +// served it (localhost during local dev, an ngrok/Cloudflare tunnel during +// device testing, etc.). Hardcoding localhost:4001 breaks any test that +// loads this worker from a non-localhost origin (the inner script is +// fetched as part of registration and produces a NetworkError otherwise). +importScripts(`${self.location.origin}/sdks/web/v16/Dev-OneSignalSDK.sw.js`); // For testing on staging // importScripts( diff --git a/preview/pageA.html b/preview/pageA.html new file mode 100644 index 000000000..179ccb547 --- /dev/null +++ b/preview/pageA.html @@ -0,0 +1,76 @@ + + + + + + SDK-4336 Repro: Page A + + + + + + + + + + + +

SDK-4336 Repro: Page A

+

+ Go to Page B +

+

+ +

+

Repro steps (per the ticket):

+
    +
  1. Add to Home Screen and open Page A.
  2. +
  3. Tap "Go to Page B".
  4. +
  5. Tap "Go to Page A".
  6. +
  7. Tap "Register" and accept the prompt.
  8. +
  9. Tap "Go to Page B".
  10. +
  11. Tap "Go to Page A" — init() should hang.
  12. +
+ + diff --git a/preview/pageB.html b/preview/pageB.html new file mode 100644 index 000000000..bbbd4f947 --- /dev/null +++ b/preview/pageB.html @@ -0,0 +1,23 @@ + + + + + + SDK-4336 Repro: Page B + + + + + + + +

SDK-4336 Repro: Page B

+

+ Go to Page A +

+

+ This page intentionally does not initialize the SDK. It just navigates back to Page A + so we can exercise the multi-page navigation flow described in SDK-4336. +

+ + diff --git a/preview/push/onesignal/OneSignalSDKWorker.js b/preview/push/onesignal/OneSignalSDKWorker.js index 0e7564295..f47bf0c0a 100644 --- a/preview/push/onesignal/OneSignalSDKWorker.js +++ b/preview/push/onesignal/OneSignalSDKWorker.js @@ -1,4 +1,4 @@ -importScripts('https://localhost:4001/sdks/web/v16/Dev-OneSignalSDK.sw.js'); +importScripts(`${self.location.origin}/sdks/web/v16/Dev-OneSignalSDK.sw.js`); // For testing on staging // importScripts( diff --git a/preview/vite.config.ts b/preview/vite.config.ts index 58a97bd00..c06151568 100644 --- a/preview/vite.config.ts +++ b/preview/vite.config.ts @@ -43,8 +43,25 @@ export default defineConfig({ // SDK fetch URL (e.g. `http://localhost:4000/...` in HTTP mode) lands here. port: useHttps ? 4001 : 4000, strictPort: true, + // HMR's WebSocket targets `wss://localhost:`, which iOS devices on a + // tunnel (ngrok, etc.) can't reach. Disabling stops the runaway + // reconnect loop that floods the console with `ws.send` rejections. + hmr: false, }, plugins: [ + { + // Vite's dev server injects `