Skip to content

Commit

Permalink
fix: support symbolic NotFoundResult
Browse files Browse the repository at this point in the history
  • Loading branch information
platosha committed Oct 1, 2024
1 parent 80cb979 commit 1c6a7e6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ export class Router<R extends AnyObject = EmptyObject> extends Resolver<R> {
}
})
.then((result) => {
if (result != null && typeof result === 'object') {
if (result != null && (typeof result === 'object' || typeof result === 'symbol')) {
// Actions like `() => import('my-view.js')` are not expected to
// end the resolution, despite the result is not empty. Checking
// the result with a whitelist of values that end the resolution.
if (result instanceof HTMLElement || 'redirect' in result || result === notFoundResult) {
if (result instanceof HTMLElement || result === notFoundResult || 'redirect' in result) {
return result;
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { EmptyObject, RequireAtLeastOne } from 'type-fest';
import type { ResolutionError } from './resolver/resolver.js';
import type { ChildrenCallback, IndexedParams, Params, ParamValue, PrimitiveParamValue } from './resolver/types.js';
import type { NotFoundResult } from './resolver/utils.js';
import type { Router } from './router.js';

export type { ResolutionError, IndexedParams, Params, ParamValue, PrimitiveParamValue };
Expand Down Expand Up @@ -54,10 +55,6 @@ export interface NavigationTrigger {
inactivate(): void;
}

export interface NotFoundResult {
notFoundResultBrand: never;
}

export type ResolutionResult<T> = T | NotFoundResult | null | undefined;

export type ActionResult = ResolutionResult<HTMLElement | PreventResult | RedirectResult> | ResolutionResult<void>;
Expand Down

0 comments on commit 1c6a7e6

Please sign in to comment.