make STALE_REACTION a `StaleReactionError extends Error`

pull/16266/head
Rich Harris 3 months ago
parent 93125942d7
commit 5e056cd00c

@ -28,7 +28,10 @@ export const LOADING_ATTR_SYMBOL = Symbol('');
export const PROXY_PATH_SYMBOL = Symbol('proxy path');
// allow users to ignore aborted signal errors if `reason.stale`
export const STALE_REACTION = { stale: true };
export const STALE_REACTION = new (class StaleReactionError extends Error {
name = 'StaleReactionError';
message = 'The reaction that called `getAbortSignal()` was re-run or destroyed';
})();
export const ELEMENT_NODE = 1;
export const TEXT_NODE = 3;

@ -7,7 +7,11 @@ export default test({
await new Promise((f) => setTimeout(f, 50));
if (variant === 'hydrate') {
assert.deepEqual(logs, ['aborted', { stale: true }]);
assert.deepEqual(logs, [
'aborted',
'StaleReactionError',
'The reaction that called `getAbortSignal()` was re-run or destroyed'
]);
}
logs.length = 0;
@ -21,6 +25,10 @@ export default test({
await new Promise((f) => setTimeout(f, 50));
assert.htmlEqual(target.innerHTML, '<button>increment</button><p>2</p>');
assert.deepEqual(logs, ['aborted', { stale: true }]);
assert.deepEqual(logs, [
'aborted',
'StaleReactionError',
'The reaction that called `getAbortSignal()` was re-run or destroyed'
]);
}
});

@ -11,7 +11,7 @@
await new Promise((f) => setTimeout(f));
if (signal.aborted) {
console.log('aborted', signal.reason);
console.log('aborted', signal.reason.name, signal.reason.message);
}
return c;

Loading…
Cancel
Save