egoist/scifi

Endless string of "undefined" prints after original content string

Closed this issue · 8 comments

gazj commented

In a statement on line 26 of src/index.js, the finished variable is compared against the value content.length. If they are equivalent, the intervals are cleared and the scifi function execution ends.

However, it seems that the finished variable can occasionally become incremented beyond the value of content.length before that statement is evaluated. When this happens, the content on the page is repeated appended with "undefined".
scifi_undefined

gazj commented

Is the demo site updated with the latest changes from pull request #6? If so, I can test for this issue on that page today.

@garylocke yes, it should be updated (since it's using the CDN version)

gazj commented

Still an issue. I am noticing that I can only reproduce it by running the demo site in a background tab, which leads me to believe it may have something to do with a race condition between the two intervals, though I'm not certain of that.

Pull request #7 introduces a check on the content character before appending it to the finished string. This should eliminate the possibility of finishedString.length ever exceeding content.length, allowing the clearInterval statements to always execute eventually.

gazj commented

Once the CDN version is updated, we can try again to reproduce this issue.

Yeah updated.

gazj commented

Great. I'm testing this in two tabs, one of which is running in the background.

gazj commented

Over an hour in the background without any issue. I'm comfortable calling this fixed for now if you are.

EDIT: Now running without issue for several hours.

gazj commented

I'm going to close this, since I am no longer able to reproduce the issue.