@uniflowed/router 0.0.0-alpha.31 → 0.0.0-alpha.32

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.
@@ -113,7 +113,7 @@ export function createPayloadReader(
113
113
  ): PayloadReader {
114
114
  const slots: Map<number, Slot> = new Map();
115
115
  let disconnect: (() => void) | null = null;
116
- let watching = false;
116
+ let reading = false;
117
117
 
118
118
  function slotFor(id: number): Slot {
119
119
  const existing = slots.get(id);
@@ -192,7 +192,7 @@ export function createPayloadReader(
192
192
  }
193
193
 
194
194
  function stop(): void {
195
- watching = false;
195
+ reading = false;
196
196
  const off = disconnect;
197
197
  disconnect = null;
198
198
  if (off != null) {
@@ -200,28 +200,39 @@ export function createPayloadReader(
200
200
  }
201
201
  }
202
202
 
203
+ function observeRest(): void {
204
+ if (!reading || disconnect != null || finished() || observe == null) {
205
+ return;
206
+ }
207
+ disconnect = observe(sweep);
208
+ if (disconnect == null) {
209
+ reading = false;
210
+ }
211
+ }
212
+
203
213
  return {
204
214
  resolve(id: number): Promise<mixed> {
205
215
  const slot = slotFor(id);
206
216
  // A reference discovered after the watch started — a client navigation
207
217
  // decoding a payload of its own — still gets whatever is already in the
208
218
  // document, so the order the two calls happen in does not matter.
209
- if (watching) {
219
+ if (reading) {
210
220
  sweep();
221
+ observeRest();
211
222
  }
212
223
  return slot.promise;
213
224
  },
214
225
  watch(): void {
215
- if (watching || slots.size === 0) {
226
+ if (reading) {
216
227
  return;
217
228
  }
218
- watching = true;
229
+ reading = true;
219
230
  sweep();
220
- if (finished() || observe == null) {
221
- watching = false;
231
+ if (slots.size > 0 && finished()) {
232
+ reading = false;
222
233
  return;
223
234
  }
224
- disconnect = observe(sweep);
235
+ observeRest();
225
236
  },
226
237
  stop,
227
238
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniflowed/router",
3
- "version": "0.0.0-alpha.31",
3
+ "version": "0.0.0-alpha.32",
4
4
  "description": "The file-system router for Flow React applications: matching, layouts, loaders, navigation, server rendering and hydration.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "react-dom": ">=19"
37
37
  },
38
38
  "dependencies": {
39
- "@uniflowed/hooks": "0.0.0-alpha.31",
40
- "@uniflowed/server": "0.0.0-alpha.31"
39
+ "@uniflowed/hooks": "0.0.0-alpha.32",
40
+ "@uniflowed/server": "0.0.0-alpha.32"
41
41
  }
42
42
  }