Skip to content

Commit

Permalink
Fixed #507, addressing Webpage stream replay bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Jul 3, 2024
1 parent bd228dd commit df8b699
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Dates are in `YYYY-MM-DD` format and versions are in [semantic versioning](http:
### Fixed

- [#509](https://github.com/wordplaydev/wordplay/issues/509) Fixed parsing regression from infinite loop fixes.
- [#507](https://github.com/wordplaydev/wordplay/issues/507) Fixed Webpage stream replay bug.

## 0.10.2 2024-06-29

Expand Down
20 changes: 12 additions & 8 deletions src/input/Webpage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export default class Webpage extends StreamValue<
}

react(event: FetchResponse) {
// If we're mirroring, and the input was a different URL, then don't replay it, since it's not relevant.
if (event.url !== this.url) return;

// Cache the response
URLResponseCache.set(event.url, { response: event, time: Date.now() });

Expand Down Expand Up @@ -160,16 +163,21 @@ export default class Webpage extends StreamValue<
}

start() {
this.get();
this.resetTimeout(true, true);
}

stop() {
this.resetTimeout();
this.resetTimeout(false, false);
return;
}

resetTimeout() {
resetTimeout(again: boolean, soon: boolean) {
if (this.timeout) clearTimeout(this.timeout);
if (again)
this.timeout = setTimeout(
() => this.get(),
soon ? 50 : Math.max(1, this.frequency) * 60 * 1000,
);
}

async get() {
Expand Down Expand Up @@ -304,11 +312,7 @@ export default class Webpage extends StreamValue<
});

// Get it again in the next period.
this.resetTimeout();
this.timeout = setTimeout(
() => this.get(),
Math.max(1, this.frequency) * 60 * 1000,
);
this.resetTimeout(true, false);
}

getType() {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/Evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ export default class Evaluator {
this.streamsByCreator.set(evaluate, [...streams, stream]);
this.creatorByStream.set(stream, evaluate);

// Start the stream if this is reactive. Otherwise, we just take it's initial value.
// Start the stream if this evaluator is reactive. Otherwise, we just take it's initial value.
if (this.reactive) stream.start();

// Listen to it so we can react to changes.
Expand Down

0 comments on commit df8b699

Please sign in to comment.