Skip to content

Commit 677a7fa

Browse files
committed
fix RouterContext export and test root warnings
Export RouterContext from the main entrypoint and run warning-producing test setup inside reactive roots so the suite stays clean. Made-with: Cursor
1 parent 671d9c5 commit 677a7fa

File tree

5 files changed

+41
-30
lines changed

5 files changed

+41
-30
lines changed

src/components.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import type { JSX } from "solid-js";
33
import { createMemo, mergeProps, splitProps } from "solid-js";
44
import {
5-
RouterContextObj,
65
useHref,
76
useLocation,
87
useNavigate,
@@ -14,8 +13,6 @@ import type {
1413
} from "./types.js";
1514
import { normalizePath } from "./utils.js";
1615

17-
export { RouterContextObj as RouterContext };
18-
1916
declare module "solid-js" {
2017
namespace JSX {
2118
interface AnchorHTMLAttributes<T> {

src/data/events.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ describe("form submit handling", () => {
447447
let mockRouter: RouterContext;
448448
let submitHandler: Function;
449449
let originalDocument: any;
450+
let disposeEvents: (() => void) | undefined;
450451

451452
beforeEach(() => {
452453
mockRouter = createMockRouter();
@@ -470,10 +471,14 @@ describe("form submit handling", () => {
470471
}
471472
} as any;
472473

473-
setupNativeEvents()(mockRouter);
474+
disposeEvents = createRoot(dispose => {
475+
setupNativeEvents()(mockRouter);
476+
return dispose;
477+
});
474478
});
475479

476480
afterEach(() => {
481+
disposeEvents?.();
477482
global.document = originalDocument;
478483
});
479484

src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export {
1212
useResolvedPath,
1313
useSearchParams,
1414
useBeforeLeave,
15-
usePreloadRoute
15+
usePreloadRoute,
16+
RouterContextObj as RouterContext
1617
} from "./routing.js";
1718
export { mergeSearchString as _mergeSearchString } from "./utils.js";
1819
export * from "./data/index.js";

src/routing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151

5252
const MAX_REDIRECTS = 100;
5353

54+
/** Consider this API opaque and internal. It is likely to change in the future. */
5455
export const RouterContextObj = createContext<RouterContext>();
5556
export const RouteContextObj = createContext<RouteContext>();
5657

test/utils.spec.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
mergeSearchString,
88
extractSearchParams
99
} from "../src/utils.js";
10+
import { createRoot } from "solid-js";
1011

1112
describe("resolvePath should", () => {
1213
test("normalize the base arg", () => {
@@ -355,38 +356,44 @@ describe("joinPaths should", () => {
355356

356357
describe("createMemoObject should", () => {
357358
test("allow listing its own keys", () => {
358-
const actual = createMemoObject(() => ({
359-
hello: "world",
360-
get throws() {
361-
throw new Error("throws");
362-
}
363-
}));
364-
expect(Object.getOwnPropertyNames(actual)).toEqual(["hello", "throws"]);
359+
createRoot(() => {
360+
const actual = createMemoObject(() => ({
361+
hello: "world",
362+
get throws() {
363+
throw new Error("throws");
364+
}
365+
}));
366+
expect(Object.getOwnPropertyNames(actual)).toEqual(["hello", "throws"]);
367+
});
365368
});
366369

367370
test("allow listing its keys", () => {
368-
const actual = createMemoObject(() => ({
369-
hello: "world",
370-
get throws() {
371-
throw new Error("throws");
372-
}
373-
}));
374-
expect(Object.keys(actual)).toEqual(["hello", "throws"]);
371+
createRoot(() => {
372+
const actual = createMemoObject(() => ({
373+
hello: "world",
374+
get throws() {
375+
throw new Error("throws");
376+
}
377+
}));
378+
expect(Object.keys(actual)).toEqual(["hello", "throws"]);
379+
});
375380
});
376381

377382
test("stringify into JSON", () => {
378-
const actual = createMemoObject(() => ({
379-
hello: "world",
380-
get getter() {
381-
return "works too";
382-
}
383-
}));
384-
expect(JSON.stringify(actual)).toEqual(
385-
JSON.stringify({
383+
createRoot(() => {
384+
const actual = createMemoObject(() => ({
386385
hello: "world",
387-
getter: "works too"
388-
})
389-
);
386+
get getter() {
387+
return "works too";
388+
}
389+
}));
390+
expect(JSON.stringify(actual)).toEqual(
391+
JSON.stringify({
392+
hello: "world",
393+
getter: "works too"
394+
})
395+
);
396+
});
390397
});
391398
});
392399

0 commit comments

Comments
 (0)