@effect/platform-browser 4.0.0-rc.109 → 4.0.0-rc.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,8 @@ const tasks = Command.make("tasks").pipe(
23
23
  workspace,
24
24
  verbose: Flag.boolean("verbose").pipe(
25
25
  Flag.withAlias("v"),
26
- Flag.withDescription("Print diagnostic output")
26
+ Flag.withDescription("Print diagnostic output"),
27
+ Flag.withDefault(false)
27
28
  )
28
29
  }),
29
30
  Command.withDescription("Track and manage tasks")
@@ -92,7 +93,8 @@ const list = Command.make(
92
93
  Flag.withDefault("open")
93
94
  ),
94
95
  json: Flag.boolean("json").pipe(
95
- Flag.withDescription("Print machine-readable output")
96
+ Flag.withDescription("Print machine-readable output"),
97
+ Flag.withDefault(false)
96
98
  )
97
99
  },
98
100
  Effect.fn(function*({ status, json }) {
@@ -2,15 +2,15 @@
2
2
  * Browser helper for running a root Effect program.
3
3
  *
4
4
  * This module exports `runMain`, a browser version of the main Effect runner.
5
- * It forwards runner options to the core runtime and adds a `beforeunload`
6
- * listener that interrupts the main fiber when the page is unloading.
5
+ * It forwards runner options to the core runtime and adds a `pagehide`
6
+ * listener that interrupts the main fiber when the document is discarded.
7
7
  *
8
8
  * @since 4.0.0
9
9
  */
10
10
  import type * as Effect from "effect/Effect";
11
11
  import { type Teardown } from "effect/Runtime";
12
12
  /**
13
- * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
13
+ * Runs an effect as the browser main program and interrupts its fiber when the document is discarded.
14
14
  *
15
15
  * **When to use**
16
16
  *
@@ -21,11 +21,12 @@ import { type Teardown } from "effect/Runtime";
21
21
  *
22
22
  * Supports both direct and curried call forms. Options are forwarded to
23
23
  * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
24
- * behavior.
24
+ * behavior. A persisted `pagehide` event is ignored because the document is
25
+ * entering the back/forward cache and may be restored.
25
26
  *
26
27
  * **Gotchas**
27
28
  *
28
- * The `beforeunload` interruption is best-effort. Browser teardown may prevent
29
+ * The `pagehide` interruption is best-effort. Browser teardown may prevent
29
30
  * asynchronous finalizers, network work, timers, or prompts from completing.
30
31
  *
31
32
  * @category running
@@ -33,7 +34,7 @@ import { type Teardown } from "effect/Runtime";
33
34
  */
34
35
  export declare const runMain: {
35
36
  /**
36
- * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
37
+ * Runs an effect as the browser main program and interrupts its fiber when the document is discarded.
37
38
  *
38
39
  * **When to use**
39
40
  *
@@ -44,11 +45,12 @@ export declare const runMain: {
44
45
  *
45
46
  * Supports both direct and curried call forms. Options are forwarded to
46
47
  * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
47
- * behavior.
48
+ * behavior. A persisted `pagehide` event is ignored because the document is
49
+ * entering the back/forward cache and may be restored.
48
50
  *
49
51
  * **Gotchas**
50
52
  *
51
- * The `beforeunload` interruption is best-effort. Browser teardown may prevent
53
+ * The `pagehide` interruption is best-effort. Browser teardown may prevent
52
54
  * asynchronous finalizers, network work, timers, or prompts from completing.
53
55
  *
54
56
  * @category running
@@ -59,7 +61,7 @@ export declare const runMain: {
59
61
  readonly teardown?: Teardown | undefined;
60
62
  }): <E, A>(effect: Effect.Effect<A, E>) => void;
61
63
  /**
62
- * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
64
+ * Runs an effect as the browser main program and interrupts its fiber when the document is discarded.
63
65
  *
64
66
  * **When to use**
65
67
  *
@@ -70,11 +72,12 @@ export declare const runMain: {
70
72
  *
71
73
  * Supports both direct and curried call forms. Options are forwarded to
72
74
  * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
73
- * behavior.
75
+ * behavior. A persisted `pagehide` event is ignored because the document is
76
+ * entering the back/forward cache and may be restored.
74
77
  *
75
78
  * **Gotchas**
76
79
  *
77
- * The `beforeunload` interruption is best-effort. Browser teardown may prevent
80
+ * The `pagehide` interruption is best-effort. Browser teardown may prevent
78
81
  * asynchronous finalizers, network work, timers, or prompts from completing.
79
82
  *
80
83
  * @category running
@@ -1 +1 @@
1
- {"version":3,"file":"BrowserRuntime.d.ts","sourceRoot":"","sources":["../src/BrowserRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,OAAO,EAAE;IACpB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,CACE,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;KACzC,GACA,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAA;IAC9C;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,CAAC,CAAC,EAAE,CAAC,EACH,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;KACzC,GACA,IAAI,CAAA;CAKP,CAAA"}
1
+ {"version":3,"file":"BrowserRuntime.d.ts","sourceRoot":"","sources":["../src/BrowserRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE3D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,OAAO,EAAE;IACpB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,CACE,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;KACzC,GACA,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAA;IAC9C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,CAAC,CAAC,EAAE,CAAC,EACH,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;KACzC,GACA,IAAI,CAAA;CAOP,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { makeRunMain } from "effect/Runtime";
2
2
  /**
3
- * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
3
+ * Runs an effect as the browser main program and interrupts its fiber when the document is discarded.
4
4
  *
5
5
  * **When to use**
6
6
  *
@@ -11,11 +11,12 @@ import { makeRunMain } from "effect/Runtime";
11
11
  *
12
12
  * Supports both direct and curried call forms. Options are forwarded to
13
13
  * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
14
- * behavior.
14
+ * behavior. A persisted `pagehide` event is ignored because the document is
15
+ * entering the back/forward cache and may be restored.
15
16
  *
16
17
  * **Gotchas**
17
18
  *
18
- * The `beforeunload` interruption is best-effort. Browser teardown may prevent
19
+ * The `pagehide` interruption is best-effort. Browser teardown may prevent
19
20
  * asynchronous finalizers, network work, timers, or prompts from completing.
20
21
  *
21
22
  * @category running
@@ -24,8 +25,10 @@ import { makeRunMain } from "effect/Runtime";
24
25
  export const runMain = /*#__PURE__*/makeRunMain(({
25
26
  fiber
26
27
  }) => {
27
- globalThis.addEventListener("beforeunload", () => {
28
- fiber.interruptUnsafe(fiber.id);
28
+ globalThis.addEventListener("pagehide", event => {
29
+ if (!event.persisted) {
30
+ fiber.interruptUnsafe(fiber.id);
31
+ }
29
32
  });
30
33
  });
31
34
  //# sourceMappingURL=BrowserRuntime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BrowserRuntime.js","names":[],"sources":["../src/BrowserRuntime.ts"],"sourcesContent":[null],"mappings":"AAUA,SAAS,WAAW,QAAuB,gBAAgB;AAE3D;;;;;;;;;;;;;;;;;;;;;;AAsBA,OAAO,MAAM,OAAO,gBA0DhB,WAAW,CAAC,CAAC;EAAE;AAAK,CAAE,KAAI;EAC5B,UAAU,CAAC,gBAAgB,CAAC,cAAc,EAAE,MAAK;IAC/C,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;EACjC,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"BrowserRuntime.js","names":[],"sources":["../src/BrowserRuntime.ts"],"sourcesContent":[null],"mappings":"AAUA,SAAS,WAAW,QAAuB,gBAAgB;AAE3D;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,MAAM,OAAO,gBA4DhB,WAAW,CAAC,CAAC;EAAE;AAAK,CAAE,KAAI;EAC5B,UAAU,CAAC,gBAAgB,CAAC,UAAU,EAAG,KAAK,IAAI;IAChD,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;MACpB,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;IACjC;EACF,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@effect/platform-browser",
3
3
  "type": "module",
4
- "version": "4.0.0-rc.109",
4
+ "version": "4.0.0-rc.110",
5
5
  "license": "MIT",
6
6
  "description": "Platform specific implementations for the browser",
7
7
  "homepage": "https://effect.website",
@@ -49,12 +49,12 @@
49
49
  "provenance": true
50
50
  },
51
51
  "peerDependencies": {
52
- "effect": "^4.0.0-rc.109"
52
+ "effect": "^4.0.0-rc.110"
53
53
  },
54
54
  "devDependencies": {
55
55
  "fake-indexeddb": "^6.2.5",
56
56
  "mock-xmlhttprequest": "^8.4.1",
57
- "effect": "^4.0.0-rc.109"
57
+ "effect": "^4.0.0-rc.110"
58
58
  },
59
59
  "scripts": {
60
60
  "codegen": "effect-utils codegen",
@@ -2,8 +2,8 @@
2
2
  * Browser helper for running a root Effect program.
3
3
  *
4
4
  * This module exports `runMain`, a browser version of the main Effect runner.
5
- * It forwards runner options to the core runtime and adds a `beforeunload`
6
- * listener that interrupts the main fiber when the page is unloading.
5
+ * It forwards runner options to the core runtime and adds a `pagehide`
6
+ * listener that interrupts the main fiber when the document is discarded.
7
7
  *
8
8
  * @since 4.0.0
9
9
  */
@@ -11,7 +11,7 @@ import type * as Effect from "effect/Effect"
11
11
  import { makeRunMain, type Teardown } from "effect/Runtime"
12
12
 
13
13
  /**
14
- * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
14
+ * Runs an effect as the browser main program and interrupts its fiber when the document is discarded.
15
15
  *
16
16
  * **When to use**
17
17
  *
@@ -22,11 +22,12 @@ import { makeRunMain, type Teardown } from "effect/Runtime"
22
22
  *
23
23
  * Supports both direct and curried call forms. Options are forwarded to
24
24
  * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
25
- * behavior.
25
+ * behavior. A persisted `pagehide` event is ignored because the document is
26
+ * entering the back/forward cache and may be restored.
26
27
  *
27
28
  * **Gotchas**
28
29
  *
29
- * The `beforeunload` interruption is best-effort. Browser teardown may prevent
30
+ * The `pagehide` interruption is best-effort. Browser teardown may prevent
30
31
  * asynchronous finalizers, network work, timers, or prompts from completing.
31
32
  *
32
33
  * @category running
@@ -34,7 +35,7 @@ import { makeRunMain, type Teardown } from "effect/Runtime"
34
35
  */
35
36
  export const runMain: {
36
37
  /**
37
- * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
38
+ * Runs an effect as the browser main program and interrupts its fiber when the document is discarded.
38
39
  *
39
40
  * **When to use**
40
41
  *
@@ -45,11 +46,12 @@ export const runMain: {
45
46
  *
46
47
  * Supports both direct and curried call forms. Options are forwarded to
47
48
  * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
48
- * behavior.
49
+ * behavior. A persisted `pagehide` event is ignored because the document is
50
+ * entering the back/forward cache and may be restored.
49
51
  *
50
52
  * **Gotchas**
51
53
  *
52
- * The `beforeunload` interruption is best-effort. Browser teardown may prevent
54
+ * The `pagehide` interruption is best-effort. Browser teardown may prevent
53
55
  * asynchronous finalizers, network work, timers, or prompts from completing.
54
56
  *
55
57
  * @category running
@@ -62,7 +64,7 @@ export const runMain: {
62
64
  }
63
65
  ): <E, A>(effect: Effect.Effect<A, E>) => void
64
66
  /**
65
- * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
67
+ * Runs an effect as the browser main program and interrupts its fiber when the document is discarded.
66
68
  *
67
69
  * **When to use**
68
70
  *
@@ -73,11 +75,12 @@ export const runMain: {
73
75
  *
74
76
  * Supports both direct and curried call forms. Options are forwarded to
75
77
  * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
76
- * behavior.
78
+ * behavior. A persisted `pagehide` event is ignored because the document is
79
+ * entering the back/forward cache and may be restored.
77
80
  *
78
81
  * **Gotchas**
79
82
  *
80
- * The `beforeunload` interruption is best-effort. Browser teardown may prevent
83
+ * The `pagehide` interruption is best-effort. Browser teardown may prevent
81
84
  * asynchronous finalizers, network work, timers, or prompts from completing.
82
85
  *
83
86
  * @category running
@@ -91,7 +94,9 @@ export const runMain: {
91
94
  }
92
95
  ): void
93
96
  } = makeRunMain(({ fiber }) => {
94
- globalThis.addEventListener("beforeunload", () => {
95
- fiber.interruptUnsafe(fiber.id)
97
+ globalThis.addEventListener("pagehide", (event) => {
98
+ if (!event.persisted) {
99
+ fiber.interruptUnsafe(fiber.id)
100
+ }
96
101
  })
97
102
  })