jazz-tools 0.18.16 → 0.18.17

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.
Files changed (36) hide show
  1. package/.svelte-kit/__package__/media/image.svelte +104 -98
  2. package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
  3. package/.svelte-kit/__package__/tests/media/image.svelte.test.js +16 -2
  4. package/.turbo/turbo-build.log +42 -42
  5. package/CHANGELOG.md +11 -0
  6. package/dist/{chunk-GRN6OAUX.js → chunk-OTWWOZMB.js} +73 -4
  7. package/dist/chunk-OTWWOZMB.js.map +1 -0
  8. package/dist/index.js +1 -1
  9. package/dist/react/index.js +2 -0
  10. package/dist/react/index.js.map +1 -1
  11. package/dist/react/media/image.d.ts.map +1 -1
  12. package/dist/react-native-core/index.js +3 -1
  13. package/dist/react-native-core/index.js.map +1 -1
  14. package/dist/react-native-core/media/image.d.ts.map +1 -1
  15. package/dist/svelte/media/image.svelte +104 -98
  16. package/dist/svelte/media/image.svelte.d.ts.map +1 -1
  17. package/dist/svelte/tests/media/image.svelte.test.js +16 -2
  18. package/dist/testing.js +1 -1
  19. package/dist/tools/implementation/refs.d.ts +1 -1
  20. package/dist/tools/implementation/refs.d.ts.map +1 -1
  21. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +4 -0
  22. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
  23. package/dist/tools/subscribe/SubscriptionScope.d.ts +7 -0
  24. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  25. package/dist/tools/subscribe/index.d.ts.map +1 -1
  26. package/package.json +4 -4
  27. package/src/react/media/image.tsx +2 -0
  28. package/src/react/tests/media/image.test.tsx +20 -2
  29. package/src/react-native-core/media/image.tsx +4 -1
  30. package/src/svelte/media/image.svelte +104 -98
  31. package/src/svelte/tests/media/image.svelte.test.ts +18 -2
  32. package/src/tools/implementation/refs.ts +27 -3
  33. package/src/tools/subscribe/CoValueCoreSubscription.ts +14 -0
  34. package/src/tools/subscribe/SubscriptionScope.ts +62 -1
  35. package/src/tools/subscribe/index.ts +8 -0
  36. package/dist/chunk-GRN6OAUX.js.map +0 -1
@@ -1,118 +1,122 @@
1
1
  <script lang="ts">
2
- import { ImageDefinition } from "jazz-tools";
3
- import { highestResAvailable } from "jazz-tools/media";
4
- import { onDestroy } from "svelte";
5
- import { CoState } from "../jazz.class.svelte";
6
- import type { ImageProps } from "./image.types.js";
7
-
8
- const { imageId, width, height, ...rest }: ImageProps = $props();
9
-
10
- const imageState = new CoState(ImageDefinition, () => imageId);
11
- let lastBestImage: [string, string] | null = null;
12
-
13
- /**
14
- * For lazy loading, we use the browser's strategy for images with loading="lazy".
15
- * We use an empty image, and when the browser triggers the load event, we load the best available image.
16
- * On page loading, if the image url is already in browser's cache, the load event is triggered immediately.
17
- * This is why we need to use a different blob url for every image.
18
- */
19
- let waitingLazyLoading = $state(rest.loading === "lazy");
20
- const lazyPlaceholder = $derived.by(() =>
21
- waitingLazyLoading ? URL.createObjectURL(emptyPixelBlob) : undefined,
22
- );
23
-
24
- const dimensions = $derived.by<{
25
- width: number | undefined;
26
- height: number | undefined;
27
- }>(() => {
28
- const originalWidth = imageState.current?.originalSize?.[0];
29
- const originalHeight = imageState.current?.originalSize?.[1];
30
-
31
- // Both width and height are "original"
32
- if (width === "original" && height === "original") {
33
- return { width: originalWidth, height: originalHeight };
34
- }
2
+ import { ImageDefinition } from "jazz-tools";
3
+ import { highestResAvailable } from "jazz-tools/media";
4
+ import { onDestroy } from "svelte";
5
+ import { CoState } from "../jazz.class.svelte";
6
+ import type { ImageProps } from "./image.types.js";
7
+
8
+ const { imageId, width, height, ...rest }: ImageProps = $props();
9
+
10
+ const imageState = new CoState(ImageDefinition, () => imageId);
11
+ let lastBestImage: [string, string] | null = null;
12
+
13
+ /**
14
+ * For lazy loading, we use the browser's strategy for images with loading="lazy".
15
+ * We use an empty image, and when the browser triggers the load event, we load the best available image.
16
+ * On page loading, if the image url is already in browser's cache, the load event is triggered immediately.
17
+ * This is why we need to use a different blob url for every image.
18
+ */
19
+ let waitingLazyLoading = $state(rest.loading === "lazy");
20
+ const lazyPlaceholder = $derived.by(() =>
21
+ waitingLazyLoading ? URL.createObjectURL(emptyPixelBlob) : undefined,
22
+ );
23
+
24
+ const dimensions = $derived.by<{
25
+ width: number | undefined;
26
+ height: number | undefined;
27
+ }>(() => {
28
+ const originalWidth = imageState.current?.originalSize?.[0];
29
+ const originalHeight = imageState.current?.originalSize?.[1];
35
30
 
36
- // Width is "original", height is a number
37
- if (width === "original" && typeof height === "number") {
38
- if (originalWidth && originalHeight) {
39
- return {
40
- width: Math.round((height * originalWidth) / originalHeight),
41
- height,
42
- };
31
+ // Both width and height are "original"
32
+ if (width === "original" && height === "original") {
33
+ return { width: originalWidth, height: originalHeight };
43
34
  }
44
- return { width: undefined, height };
45
- }
46
35
 
47
- // Height is "original", width is a number
48
- if (height === "original" && typeof width === "number") {
49
- if (originalWidth && originalHeight) {
50
- return {
51
- width,
52
- height: Math.round((width * originalHeight) / originalWidth),
53
- };
36
+ // Width is "original", height is a number
37
+ if (width === "original" && typeof height === "number") {
38
+ if (originalWidth && originalHeight) {
39
+ return {
40
+ width: Math.round((height * originalWidth) / originalHeight),
41
+ height,
42
+ };
43
+ }
44
+ return { width: undefined, height };
54
45
  }
55
- return { width, height: undefined };
56
- }
57
46
 
58
- // In all other cases, use the property value:
59
- return {
60
- width: width === "original" ? originalWidth : width,
61
- height: height === "original" ? originalHeight : height,
62
- };
63
- });
47
+ // Height is "original", width is a number
48
+ if (height === "original" && typeof width === "number") {
49
+ if (originalWidth && originalHeight) {
50
+ return {
51
+ width,
52
+ height: Math.round((width * originalHeight) / originalWidth),
53
+ };
54
+ }
55
+ return { width, height: undefined };
56
+ }
64
57
 
65
- const src = $derived.by(() => {
66
- if (waitingLazyLoading) {
67
- return lazyPlaceholder;
68
- }
58
+ // In all other cases, use the property value:
59
+ return {
60
+ width: width === "original" ? originalWidth : width,
61
+ height: height === "original" ? originalHeight : height,
62
+ };
63
+ });
69
64
 
70
- const image = imageState.current;
71
- if (!image) return undefined;
65
+ const src = $derived.by(() => {
66
+ if (waitingLazyLoading) {
67
+ return lazyPlaceholder;
68
+ }
72
69
 
73
- const bestImage = highestResAvailable(
74
- image,
75
- dimensions.width || dimensions.height || 9999,
76
- dimensions.height || dimensions.width || 9999,
77
- );
70
+ const image = imageState.current;
71
+ if (image === undefined)
72
+ return "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
78
73
 
79
- if (!bestImage) return image.placeholderDataURL;
80
- if (lastBestImage?.[0] === bestImage.image.$jazz.id) return lastBestImage?.[1];
74
+ if (!image) return undefined;
81
75
 
82
- const blob = bestImage.image.toBlob();
76
+ const bestImage = highestResAvailable(
77
+ image,
78
+ dimensions.width || dimensions.height || 9999,
79
+ dimensions.height || dimensions.width || 9999,
80
+ );
83
81
 
84
- if (blob) {
85
- const url = URL.createObjectURL(blob);
86
- revokeObjectURL(lastBestImage?.[1]);
87
- lastBestImage = [bestImage.image.$jazz.id, url];
88
- return url;
89
- }
82
+ if (!bestImage) return image.placeholderDataURL;
83
+ if (lastBestImage?.[0] === bestImage.image.$jazz.id)
84
+ return lastBestImage?.[1];
85
+
86
+ const blob = bestImage.image.toBlob();
87
+
88
+ if (blob) {
89
+ const url = URL.createObjectURL(blob);
90
+ revokeObjectURL(lastBestImage?.[1]);
91
+ lastBestImage = [bestImage.image.$jazz.id, url];
92
+ return url;
93
+ }
90
94
 
91
- return image.placeholderDataURL;
92
- });
95
+ return image.placeholderDataURL;
96
+ });
93
97
 
94
- // Cleanup object URL on component destroy
95
- onDestroy(() => {
96
- revokeObjectURL(lastBestImage?.[1]);
97
- });
98
+ // Cleanup object URL on component destroy
99
+ onDestroy(() => {
100
+ revokeObjectURL(lastBestImage?.[1]);
101
+ });
98
102
 
99
- function revokeObjectURL(url: string | undefined) {
100
- if (url && url.startsWith("blob:")) {
101
- URL.revokeObjectURL(url);
103
+ function revokeObjectURL(url: string | undefined) {
104
+ if (url && url.startsWith("blob:")) {
105
+ URL.revokeObjectURL(url);
106
+ }
102
107
  }
103
- }
104
108
 
105
- const emptyPixelBlob = new Blob(
106
- [
107
- Uint8Array.from(
108
- atob(
109
- "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==",
109
+ const emptyPixelBlob = new Blob(
110
+ [
111
+ Uint8Array.from(
112
+ atob(
113
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==",
114
+ ),
115
+ (c) => c.charCodeAt(0),
110
116
  ),
111
- (c) => c.charCodeAt(0),
112
- ),
113
- ],
114
- { type: "image/png" },
115
- );
117
+ ],
118
+ { type: "image/png" },
119
+ );
116
120
  </script>
117
121
 
118
122
  <img
@@ -120,6 +124,8 @@ const emptyPixelBlob = new Blob(
120
124
  width={dimensions.width}
121
125
  height={dimensions.height}
122
126
  alt={rest.alt}
123
- onload={() => {waitingLazyLoading = false}}
127
+ onload={() => {
128
+ waitingLazyLoading = false;
129
+ }}
124
130
  {...rest}
125
131
  />
@@ -1 +1 @@
1
- {"version":3,"file":"image.svelte.d.ts","sourceRoot":"","sources":["../../../../src/svelte/media/image.svelte.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AA2HnD,QAAA,MAAM,KAAK,gDAAsC,CAAC;AAClD,KAAK,KAAK,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AACtC,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"image.svelte.d.ts","sourceRoot":"","sources":["../../../../src/svelte/media/image.svelte.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAiInD,QAAA,MAAM,KAAK,gDAAsC,CAAC;AAClD,KAAK,KAAK,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AACtC,eAAe,KAAK,CAAC"}
@@ -10,7 +10,7 @@ describe("Image", async () => {
10
10
  });
11
11
  const renderWithAccount = (props) => render(Image, props, { account });
12
12
  describe("initial rendering", () => {
13
- it("should render nothing if coValue is not found", async () => {
13
+ it("should render a blank placeholder while waiting for the coValue to load", async () => {
14
14
  const { container } = renderWithAccount({
15
15
  imageId: "co_zMTubMby3QiKDYnW9e2BEXW7Xaq",
16
16
  alt: "test",
@@ -20,7 +20,21 @@ describe("Image", async () => {
20
20
  expect(img.getAttribute("width")).toBe(null);
21
21
  expect(img.getAttribute("height")).toBe(null);
22
22
  expect(img.alt).toBe("test");
23
- expect(img.src).toBe("");
23
+ expect(img.src).toBe("data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
24
+ });
25
+ it("should render nothing if coValue is not found", async () => {
26
+ const { container } = renderWithAccount({
27
+ imageId: "co_zMTubMby3QiKDYnW9e2BEXW7Xaq",
28
+ alt: "test",
29
+ });
30
+ await waitFor(() => {
31
+ const img = container.querySelector("img");
32
+ expect(img).toBeDefined();
33
+ expect(img.getAttribute("width")).toBe(null);
34
+ expect(img.getAttribute("height")).toBe(null);
35
+ expect(img.alt).toBe("test");
36
+ expect(img.src).toBe("");
37
+ });
24
38
  });
25
39
  it("should render an empty image if the image is not loaded yet", async () => {
26
40
  const original = FileStream.create({ owner: account.$jazz.owner });
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.18.16 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.18.17 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
3
  > tsup && pnpm types && pnpm build:svelte
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
@@ -114,24 +114,17 @@
114
114
  ESM Build start
115
115
  CLI Cleaning output folder
116
116
  ESM Build start
117
- ESM dist/tiptap/index.js 564.00 B
118
- ESM dist/tiptap/index.js.map 1.21 KB
119
- ESM ⚡️ Build success in 13ms
120
117
  ESM dist/react/ssr.js 688.00 B
121
118
  ESM dist/react/ssr.js.map 1.12 KB
119
+ ESM ⚡️ Build success in 20ms
120
+ ESM dist/tiptap/index.js 564.00 B
121
+ ESM dist/tiptap/index.js.map 1.21 KB
122
122
  ESM ⚡️ Build success in 15ms
123
123
  ESM dist/worker/index.js 3.19 KB
124
124
  ESM dist/worker/edge-wasm.js 215.00 B
125
125
  ESM dist/worker/index.js.map 6.17 KB
126
126
  ESM dist/worker/edge-wasm.js.map 434.00 B
127
- ESM ⚡️ Build success in 20ms
128
- ESM dist/better-auth/auth/client.js 4.44 KB
129
- ESM dist/better-auth/auth/react.js 799.00 B
130
- ESM dist/better-auth/auth/server.js 8.36 KB
131
- ESM dist/better-auth/auth/client.js.map 8.24 KB
132
- ESM dist/better-auth/auth/react.js.map 2.04 KB
133
- ESM dist/better-auth/auth/server.js.map 15.29 KB
134
- ESM ⚡️ Build success in 18ms
127
+ ESM ⚡️ Build success in 16ms
135
128
  ESM dist/media/index.js 236.00 B
136
129
  ESM dist/media/index.browser.js 2.79 KB
137
130
  ESM dist/media/index.native.js 2.90 KB
@@ -142,70 +135,77 @@
142
135
  ESM dist/media/index.native.js.map 6.09 KB
143
136
  ESM dist/media/index.server.js.map 6.37 KB
144
137
  ESM dist/media/chunk-W3S526L3.js.map 16.57 KB
145
- ESM ⚡️ Build success in 34ms
138
+ ESM ⚡️ Build success in 31ms
139
+ ESM dist/better-auth/auth/client.js 4.44 KB
140
+ ESM dist/better-auth/auth/react.js 799.00 B
141
+ ESM dist/better-auth/auth/server.js 8.36 KB
142
+ ESM dist/better-auth/auth/client.js.map 8.24 KB
143
+ ESM dist/better-auth/auth/react.js.map 2.04 KB
144
+ ESM dist/better-auth/auth/server.js.map 15.29 KB
145
+ ESM ⚡️ Build success in 27ms
146
+ ESM dist/react-native/index.js 2.53 KB
147
+ ESM dist/react-native/crypto.js 161.00 B
148
+ ESM dist/react-native/testing.js 120.00 B
149
+ ESM dist/react-native/index.js.map 5.68 KB
150
+ ESM dist/react-native/crypto.js.map 197.00 B
151
+ ESM dist/react-native/testing.js.map 176.00 B
152
+ ESM ⚡️ Build success in 35ms
146
153
  ESM dist/react-core/index.js 10.72 KB
147
154
  ESM dist/react-core/testing.js 1.17 KB
148
155
  ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
149
156
  ESM dist/react-core/index.js.map 33.90 KB
150
157
  ESM dist/react-core/testing.js.map 1.82 KB
151
158
  ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
152
- ESM ⚡️ Build success in 36ms
159
+ ESM ⚡️ Build success in 32ms
153
160
  ESM dist/expo/index.js 4.68 KB
154
161
  ESM dist/expo/testing.js 112.00 B
155
162
  ESM dist/expo/crypto.js 153.00 B
156
163
  ESM dist/expo/index.js.map 10.23 KB
157
164
  ESM dist/expo/testing.js.map 168.00 B
158
165
  ESM dist/expo/crypto.js.map 189.00 B
159
- ESM ⚡️ Build success in 42ms
160
- ESM dist/react-native/index.js 2.53 KB
161
- ESM dist/react-native/crypto.js 161.00 B
162
- ESM dist/react-native/testing.js 120.00 B
163
- ESM dist/react-native/index.js.map 5.68 KB
164
- ESM dist/react-native/crypto.js.map 197.00 B
165
- ESM dist/react-native/testing.js.map 176.00 B
166
- ESM ⚡️ Build success in 38ms
166
+ ESM ⚡️ Build success in 44ms
167
167
  ESM dist/browser/index.js 13.64 KB
168
168
  ESM dist/browser/index.js.map 29.14 KB
169
- ESM ⚡️ Build success in 43ms
169
+ ESM ⚡️ Build success in 46ms
170
170
  ESM dist/better-auth/database-adapter/index.js 26.34 KB
171
171
  ESM dist/better-auth/database-adapter/index.js.map 57.62 KB
172
- ESM ⚡️ Build success in 43ms
173
- ESM dist/react/testing.js 122.00 B
174
- ESM dist/react/index.js 24.76 KB
175
- ESM dist/react/testing.js.map 165.00 B
176
- ESM dist/react/index.js.map 53.56 KB
177
- ESM ⚡️ Build success in 49ms
178
- ESM dist/react-native-core/index.js 18.03 KB
179
- ESM dist/react-native-core/testing.js 119.00 B
172
+ ESM ⚡️ Build success in 39ms
173
+ ESM dist/react-native-core/index.js 18.13 KB
180
174
  ESM dist/react-native-core/crypto.js 2.10 KB
181
- ESM dist/react-native-core/index.js.map 36.85 KB
182
- ESM dist/react-native-core/testing.js.map 175.00 B
175
+ ESM dist/react-native-core/testing.js 119.00 B
176
+ ESM dist/react-native-core/index.js.map 36.96 KB
183
177
  ESM dist/react-native-core/crypto.js.map 4.25 KB
184
- ESM ⚡️ Build success in 49ms
178
+ ESM dist/react-native-core/testing.js.map 175.00 B
179
+ ESM ⚡️ Build success in 51ms
180
+ ESM dist/react/index.js 24.88 KB
181
+ ESM dist/react/testing.js 122.00 B
182
+ ESM dist/react/testing.js.map 165.00 B
183
+ ESM dist/react/index.js.map 53.71 KB
184
+ ESM ⚡️ Build success in 52ms
185
185
  ESM dist/prosemirror/index.js 77.76 KB
186
186
  ESM dist/prosemirror/index.js.map 307.20 KB
187
- ESM ⚡️ Build success in 52ms
187
+ ESM ⚡️ Build success in 54ms
188
188
  ESM dist/inspector/index.js 69.71 KB
189
189
  ESM dist/inspector/index.js.map 121.38 KB
190
- ESM ⚡️ Build success in 63ms
190
+ ESM ⚡️ Build success in 64ms
191
+ ESM dist/chunk-OTWWOZMB.js 176.08 KB
191
192
  ESM dist/testing.js 7.17 KB
192
193
  ESM dist/index.js 26.13 KB
193
- ESM dist/chunk-GRN6OAUX.js 174.37 KB
194
+ ESM dist/chunk-OTWWOZMB.js.map 419.55 KB
194
195
  ESM dist/testing.js.map 14.10 KB
195
196
  ESM dist/index.js.map 52.92 KB
196
- ESM dist/chunk-GRN6OAUX.js.map 415.70 KB
197
- ESM ⚡️ Build success in 80ms
197
+ ESM ⚡️ Build success in 82ms
198
198
  ESM dist/inspector/register-custom-element.js 218.00 B
199
199
  ESM dist/inspector/register-custom-element.js.map 314.00 B
200
200
  ESM dist/inspector/custom-element-G6SPZEBR.js 1.54 MB
201
201
  ESM dist/inspector/custom-element-G6SPZEBR.js.map 2.36 MB
202
- ESM ⚡️ Build success in 122ms
202
+ ESM ⚡️ Build success in 123ms
203
203
 
204
- > jazz-tools@0.18.16 types /home/runner/_work/jazz/jazz/packages/jazz-tools
204
+ > jazz-tools@0.18.17 types /home/runner/_work/jazz/jazz/packages/jazz-tools
205
205
  > tsc --outDir dist
206
206
 
207
207
 
208
- > jazz-tools@0.18.16 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
208
+ > jazz-tools@0.18.17 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
209
209
  > rm -rf dist/svelte && svelte-package -i src/svelte -o dist/svelte --tsconfig tsconfig.svelte.json
210
210
 
211
211
  src/svelte -> dist/svelte
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.18.17
4
+
5
+ ### Patch Changes
6
+
7
+ - 75d1afa: Fix an issue where a flash of alt text displays while an image definition is loading from storage
8
+ - 8aa4acd: Optimized the inactive subscriptions, improving performance of updates on created and loaded values by 2.5x
9
+ - Updated dependencies [925da72]
10
+ - cojson@0.18.17
11
+ - cojson-storage-indexeddb@0.18.17
12
+ - cojson-transport-ws@0.18.17
13
+
3
14
  ## 0.18.16
4
15
 
5
16
  ### Patch Changes
@@ -3317,8 +3317,21 @@ var Ref = class {
3317
3317
  }
3318
3318
  async load() {
3319
3319
  const subscriptionScope = getSubscriptionScope(this.parent);
3320
- subscriptionScope.subscribeToId(this.id, this.schema);
3321
- const node = subscriptionScope.childNodes.get(this.id);
3320
+ let node;
3321
+ if (subscriptionScope.closed) {
3322
+ node = new SubscriptionScope(
3323
+ subscriptionScope.node,
3324
+ true,
3325
+ this.id,
3326
+ this.schema,
3327
+ subscriptionScope.skipRetry,
3328
+ subscriptionScope.bestEffortResolution,
3329
+ subscriptionScope.unstable_branch
3330
+ );
3331
+ } else {
3332
+ subscriptionScope.subscribeToId(this.id, this.schema);
3333
+ node = subscriptionScope.childNodes.get(this.id);
3334
+ }
3322
3335
  if (!node) {
3323
3336
  return null;
3324
3337
  }
@@ -3338,6 +3351,9 @@ var Ref = class {
3338
3351
  unsubscribe();
3339
3352
  resolve(null);
3340
3353
  }
3354
+ if (subscriptionScope.closed) {
3355
+ node.destroy();
3356
+ }
3341
3357
  });
3342
3358
  });
3343
3359
  }
@@ -3523,6 +3539,17 @@ var CoValueCoreSubscription = class {
3523
3539
  this.source = localNode.getCoValue(id);
3524
3540
  this.initializeSubscription();
3525
3541
  }
3542
+ /**
3543
+ * Rehydrates the subscription by resetting the unsubscribed flag and initializing the subscription again
3544
+ */
3545
+ pullValue() {
3546
+ if (!this.unsubscribed) {
3547
+ return;
3548
+ }
3549
+ this.unsubscribed = false;
3550
+ this.initializeSubscription();
3551
+ this.unsubscribe();
3552
+ }
3526
3553
  /**
3527
3554
  * Main entry point for subscription initialization.
3528
3555
  * Determines the subscription strategy based on current availability and branch requirements.
@@ -3753,6 +3780,7 @@ var SubscriptionScope = class _SubscriptionScope {
3753
3780
  this.totalValidTransactions = 0;
3754
3781
  this.migrated = false;
3755
3782
  this.migrating = false;
3783
+ this.closed = false;
3756
3784
  this.silenceUpdates = false;
3757
3785
  this.handleChildUpdate = (id, value, key) => {
3758
3786
  if (value.type === "unloaded") {
@@ -3788,7 +3816,6 @@ var SubscriptionScope = class _SubscriptionScope {
3788
3816
  lastUpdate = value;
3789
3817
  if (skipRetry && value === "unavailable") {
3790
3818
  this.handleUpdate(value);
3791
- this.destroy();
3792
3819
  return;
3793
3820
  }
3794
3821
  if (!this.migrated && value !== "unavailable") {
@@ -3992,8 +4019,37 @@ var SubscriptionScope = class _SubscriptionScope {
3992
4019
  isSubscribedToId(id) {
3993
4020
  return this.idsSubscribed.has(id) || this.childValues.has(id) || this.pendingAutoloadedChildren.has(id) || this.pendingLoadedChildren.has(id);
3994
4021
  }
4022
+ /**
4023
+ * Checks if the currently unloaded value has got some updates
4024
+ *
4025
+ * Used to make the autoload work on closed subscription scopes
4026
+ */
4027
+ pullValue(listener) {
4028
+ if (!this.closed) {
4029
+ throw new Error("Cannot pull a non-closed subscription scope");
4030
+ }
4031
+ if (this.value.type === "loaded") {
4032
+ return;
4033
+ }
4034
+ this.subscription.pullValue();
4035
+ const value = this.getCurrentValue();
4036
+ if (value) {
4037
+ listener({
4038
+ type: "loaded",
4039
+ value,
4040
+ id: this.id
4041
+ });
4042
+ }
4043
+ }
3995
4044
  subscribeToId(id, descriptor) {
3996
4045
  if (this.isSubscribedToId(id)) {
4046
+ if (!this.closed) {
4047
+ return;
4048
+ }
4049
+ const child2 = this.childNodes.get(id);
4050
+ if (child2) {
4051
+ child2.pullValue((value) => this.handleChildUpdate(id, value));
4052
+ }
3997
4053
  return;
3998
4054
  }
3999
4055
  this.idsSubscribed.add(id);
@@ -4011,6 +4067,9 @@ var SubscriptionScope = class _SubscriptionScope {
4011
4067
  );
4012
4068
  this.childNodes.set(id, child);
4013
4069
  child.setListener((value) => this.handleChildUpdate(id, value));
4070
+ if (this.closed) {
4071
+ child.destroy();
4072
+ }
4014
4073
  this.silenceUpdates = false;
4015
4074
  }
4016
4075
  loadChildren() {
@@ -4200,8 +4259,12 @@ var SubscriptionScope = class _SubscriptionScope {
4200
4259
  );
4201
4260
  this.childNodes.set(id, child);
4202
4261
  child.setListener((value) => this.handleChildUpdate(id, value, key));
4262
+ if (this.closed) {
4263
+ child.destroy();
4264
+ }
4203
4265
  }
4204
4266
  destroy() {
4267
+ this.closed = true;
4205
4268
  this.subscription.unsubscribe();
4206
4269
  this.subscribers.clear();
4207
4270
  this.childNodes.forEach((child) => child.destroy());
@@ -4227,12 +4290,18 @@ function getSubscriptionScope(value) {
4227
4290
  enumerable: false,
4228
4291
  configurable: false
4229
4292
  });
4293
+ newSubscriptionScope.destroy();
4230
4294
  return newSubscriptionScope;
4231
4295
  }
4232
4296
  function accessChildByKey(parent, childId, key) {
4233
4297
  const subscriptionScope = getSubscriptionScope(parent);
4298
+ const node = subscriptionScope.childNodes.get(childId);
4234
4299
  if (!subscriptionScope.isSubscribedToId(childId)) {
4235
4300
  subscriptionScope.subscribeToKey(key);
4301
+ } else if (node && node.closed) {
4302
+ node.pullValue(
4303
+ (value2) => subscriptionScope.handleChildUpdate(childId, value2)
4304
+ );
4236
4305
  }
4237
4306
  const value = subscriptionScope.childValues.get(childId);
4238
4307
  if (value?.type === "loaded") {
@@ -6078,4 +6147,4 @@ export {
6078
6147
  JazzContextManager
6079
6148
  };
6080
6149
  /* istanbul ignore file -- @preserve */
6081
- //# sourceMappingURL=chunk-GRN6OAUX.js.map
6150
+ //# sourceMappingURL=chunk-OTWWOZMB.js.map