From acc26756288dc685c3d48f836147b0cb2d697229 Mon Sep 17 00:00:00 2001 From: aaa_eee Date: Thu, 8 Aug 2024 18:49:26 +0200 Subject: [PATCH 1/5] chore: bump typescript version --- pnpm-lock.yaml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 61f2b340..ac95a633 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,7 +1,7 @@ lockfileVersion: '9.0' settings: - autoInstallPeers: true + autoInstallPeers: false excludeLinksFromLockfile: false importers: @@ -2008,14 +2008,14 @@ snapshots: '@rollup/plugin-terser@0.4.4(rollup@3.29.4)': dependencies: - rollup: 3.29.4 serialize-javascript: 6.0.1 smob: 1.4.1 terser: 5.21.0 + optionalDependencies: + rollup: 3.29.4 '@rushstack/node-core-library@3.61.0(@types/node@18.18.4)': dependencies: - '@types/node': 18.18.4 colors: 1.2.5 fs-extra: 7.0.1 import-lazy: 4.0.0 @@ -2023,6 +2023,8 @@ snapshots: resolve: 1.22.8 semver: 7.5.4 z-schema: 5.0.5 + optionalDependencies: + '@types/node': 18.18.4 '@rushstack/rig-package@0.5.1': dependencies: @@ -2039,6 +2041,7 @@ snapshots: '@samverschueren/stream-to-observable@0.3.1(rxjs@6.6.7)': dependencies: any-observable: 0.3.0(rxjs@6.6.7) + optionalDependencies: rxjs: 6.6.7 transitivePeerDependencies: - zenObservable @@ -2146,11 +2149,11 @@ snapshots: color-convert: 2.0.1 any-observable@0.3.0(rxjs@6.6.7): - dependencies: + optionalDependencies: rxjs: 6.6.7 any-observable@0.5.1(rxjs@6.6.7): - dependencies: + optionalDependencies: rxjs: 6.6.7 argparse@1.0.10: From 6e570d603e335e7ea1ea1be18753e57d41180200 Mon Sep 17 00:00:00 2001 From: aaa_eee Date: Tue, 3 Sep 2024 16:39:10 +0200 Subject: [PATCH 2/5] feat: configurable fallback timeout --- src/lib/main/snippet.ts | 2 +- src/lib/types.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/main/snippet.ts b/src/lib/main/snippet.ts index 5cbc07b0..d0bdb7c9 100644 --- a/src/lib/main/snippet.ts +++ b/src/lib/main/snippet.ts @@ -41,7 +41,7 @@ export function snippet( top!.dispatchEvent(new CustomEvent('pt1', { detail: win })); } else { // set a timeout to fire if PT hasn't initialized in Xms - timeout = setTimeout(fallback, 9999); + timeout = setTimeout(fallback, config?.fallbackTimeout || 9999); doc.addEventListener('pt0', clearFallback); if (useAtomics) { diff --git a/src/lib/types.ts b/src/lib/types.ts index 42d95dcd..91060e19 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -444,6 +444,11 @@ export interface PartytownConfig { * https://partytown.builder.io/forwarding-events */ forward?: PartytownForwardProperty[]; + /** + * Timeout in ms before the initialization considered failed and the fallback solution is executed + * Default: 9999 + */ + fallbackTimeout?: number; /** * The css selector where the sandbox should be placed. * Default: body From 2c9237901d893220dd2a90afc675ba9737c44ff9 Mon Sep 17 00:00:00 2001 From: aaa_eee Date: Tue, 3 Sep 2024 16:49:32 +0200 Subject: [PATCH 3/5] docs: add fallbackTimeout description --- docs/configuration.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index b83a0867..a12288f9 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -7,11 +7,12 @@ Partytown does not require a config for it to work, however a config can be set | Config | Description | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `debug` | When `true`, Partytown scripts are not inlined and not minified. See the [Debugging](/debugging) docs on how to enable more logging. | -| `forward` | An array of strings representing function calls on the main thread to forward to the web worker. See [Forwarding Events and Triggers](/forwarding-events) for more info. | +| `forward` | An array of strings representing function calls on the main thread to forward to the web worker. See [Forwarding Events and Triggers](/forwarding-events) for more info. | | `lib` | Path where the Partytown library can be found your server. Note that the path must both start and end with a `/` character, and the files must be hosted from the same origin as the webpage. Default is `/~partytown/` | | `loadScriptsOnMainThread` | An array of strings or regular expressions (RegExp) used to filter out which script are executed via Partytown and the main thread. An example is as follows: `loadScriptsOnMainThread: ["https://test.com/analytics.js", "inline-script-id", /regex-matched-script\.js/]`.| | `resolveUrl` | Hook that is called to resolve URLs which can be used to modify URLs. The hook uses the API: `resolveUrl(url: URL, location: URL, method: string)`. See the [Proxying Requests](/proxying-requests) for more information. | | `nonce` | The nonce property may be set on script elements created by Partytown. This should be set only when dealing with content security policies and when the use of `unsafe-inline` is disabled (using `nonce-*` instead). | +| `fallbackTimeout` | A timeout in ms until Partytown initialization is considered as failed & fallbacks to the regular execution in main thread. Default is 9999 | ## Vanilla Config From 457c432bc6a6e307d12bf15b3762d3429d693ab7 Mon Sep 17 00:00:00 2001 From: aaa_eee Date: Tue, 3 Sep 2024 16:54:38 +0200 Subject: [PATCH 4/5] docs: add fallbackTimeout public interface --- src/integration/api.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/integration/api.md b/src/integration/api.md index 9ffe0f06..21dfd32a 100644 --- a/src/integration/api.md +++ b/src/integration/api.md @@ -20,6 +20,7 @@ export interface PartytownConfig { // (undocumented) apply?: ApplyHook; debug?: boolean; + fallbackTimeout?: number; forward?: PartytownForwardProperty[]; // (undocumented) get?: GetHook; From ac7bce9a69b9c5e42663cd6a34fabdcc3d2fd7f5 Mon Sep 17 00:00:00 2001 From: aaa_eee Date: Tue, 3 Sep 2024 16:56:06 +0200 Subject: [PATCH 5/5] Revert "chore: bump typescript version" This reverts commit acc26756288dc685c3d48f836147b0cb2d697229. --- pnpm-lock.yaml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ac95a633..61f2b340 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,7 +1,7 @@ lockfileVersion: '9.0' settings: - autoInstallPeers: false + autoInstallPeers: true excludeLinksFromLockfile: false importers: @@ -2008,14 +2008,14 @@ snapshots: '@rollup/plugin-terser@0.4.4(rollup@3.29.4)': dependencies: + rollup: 3.29.4 serialize-javascript: 6.0.1 smob: 1.4.1 terser: 5.21.0 - optionalDependencies: - rollup: 3.29.4 '@rushstack/node-core-library@3.61.0(@types/node@18.18.4)': dependencies: + '@types/node': 18.18.4 colors: 1.2.5 fs-extra: 7.0.1 import-lazy: 4.0.0 @@ -2023,8 +2023,6 @@ snapshots: resolve: 1.22.8 semver: 7.5.4 z-schema: 5.0.5 - optionalDependencies: - '@types/node': 18.18.4 '@rushstack/rig-package@0.5.1': dependencies: @@ -2041,7 +2039,6 @@ snapshots: '@samverschueren/stream-to-observable@0.3.1(rxjs@6.6.7)': dependencies: any-observable: 0.3.0(rxjs@6.6.7) - optionalDependencies: rxjs: 6.6.7 transitivePeerDependencies: - zenObservable @@ -2149,11 +2146,11 @@ snapshots: color-convert: 2.0.1 any-observable@0.3.0(rxjs@6.6.7): - optionalDependencies: + dependencies: rxjs: 6.6.7 any-observable@0.5.1(rxjs@6.6.7): - optionalDependencies: + dependencies: rxjs: 6.6.7 argparse@1.0.10: