Skip to content

Commit

Permalink
Merge 5fe4bf5 into bfbd002
Browse files Browse the repository at this point in the history
  • Loading branch information
Exelord committed Feb 12, 2023
2 parents bfbd002 + 5fe4bf5 commit fde96f2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ export function onError(fn: (err: any) => void): void {
console.warn("error handlers created outside a `createRoot` or `render` will never be run");
else if (Owner.context === null) Owner.context = { [ERROR]: [fn] };
else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn];
else Owner.context[ERROR].push(fn);
else Owner.context[ERROR].unshift(fn);
}

export function getListener() {
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/src/server/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function onError(fn: (err: any) => void): void {
if (Owner) {
if (Owner.context === null) Owner.context = { [ERROR]: [fn] };
else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn];
else Owner.context[ERROR].push(fn);
else Owner.context[ERROR].unshift(fn);
}
}

Expand Down
10 changes: 4 additions & 6 deletions packages/solid/test/signals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,19 +453,17 @@ describe("onError", () => {
});

test("With multiple error handlers", () => {
let errored = false;
let errored2 = false;
const errors: string[] = [];
expect(() =>
createRoot(() => {
createEffect(() => {
onError(() => (errored = true));
onError(() => (errored2 = true));
onError(() => errors.push("first"));
onError(() => errors.push("second"));
throw "fail";
});
})
).not.toThrow("fail");
expect(errored).toBe(true);
expect(errored2).toBe(true);
expect(errors).toEqual(["second", "first"]);
});

test("In update effect", () => {
Expand Down

0 comments on commit fde96f2

Please sign in to comment.