fix: prevent unbounded recursion on boot - #2230
Conversation
Co-authored-by: Copilot <copilot@github.com>
|
Ooh, good idea. I think the chances that this is addressing a thing which is in fact happening are low, but good safety. |
|
Some alternative (non-recursive) forms (not tested, may have typos): const waitForReactLoaded = async () => {
for (let attempts = 0; attempts < MAX_BOOT_ATTEMPTS; attempts++) {
if (isReactLoaded()) return;
await new Promise(window.requestAnimationFrame);
}
throw new Error('XKit Rewritten boot failed; React did not load after 10+ seconds.');
};
if (redpop) {
waitForReactLoaded()
.then(init)
.catch(console.error);
} const waitForReactLoaded = async () => {
let attempts = 0;
while (!isReactLoaded()) {
if (++attempts <= MAX_BOOT_ATTEMPTS) {
throw new Error('XKit Rewritten boot failed; React did not load after 10+ seconds.');
}
await new Promise(window.requestAnimationFrame);
}
};
if (redpop) {
waitForReactLoaded()
.then(init)
.catch(console.error);
}edit: we could also call await waitForReactLoaded() in init if that feels cleaner. |
|
(How do I feel about this commit coauthor and its legal interaction with the gpl license? I'm officially Not Sure.) |
marcustyphoon
left a comment
There was a problem hiding this comment.
Well... I can't get isReactLoaded() to ever return false in practice, so this code pah is untested. I hacked it to return false 90% of the time and it seems to work fine, so... success?
Co-authored-by: marcustyphoon <marcustyphoon@gmail.com>
Did the same for the latest commit; turns out you can't use |
|
Interesting. I guess I've always used plain requestAnimationFrame. Alternatively, if that also doesn't work, I've hardcore mandala effected myself. |
|
(Surely it's not a module vs script thing?) |
|
Description
A theoretical improvement. Caps the maximum number of boot attempts at 3600, which is a very safe one minute on a 60Hz display, decreasing as refresh rate increases.
I think it's very safe to assume that devices able to output 360 frames per second can load React in a lot less than 10 seconds.
I would be very interested in revisiting #1971 after this.
Testing steps
(Proving that
"run_at": "document_end"is working as intended)