diff --git a/packages/waku/src/minimal/client.ts b/packages/waku/src/minimal/client.ts index af9376a26..f80de088c 100644 --- a/packages/waku/src/minimal/client.ts +++ b/packages/waku/src/minimal/client.ts @@ -272,7 +272,9 @@ const InnerSlot = ({ return renderSlot(elements); }; -const InnerErr = ({ err }: { err: unknown }) => { +const ErrorContext = createContext(undefined); +export const ThrowError_UNSTABLE = () => { + const err = use(ErrorContext); throw err; }; @@ -315,11 +317,7 @@ export const Slot = ({ if (fallback) { if (err) { // HACK I'm not sure if this is the right way - return createElement( - ChildrenContextProvider, - { value: createElement(InnerErr, { err }) }, - fallback, - ); + return createElement(ErrorContext.Provider, { value: err }, fallback); } return fallback; } diff --git a/packages/waku/src/router/create-pages.ts b/packages/waku/src/router/create-pages.ts index 025fd699c..ac641cc4f 100644 --- a/packages/waku/src/router/create-pages.ts +++ b/packages/waku/src/router/create-pages.ts @@ -15,7 +15,7 @@ import type { GetSlugs, PropsForPages, } from './create-pages-utils/inferred-path-types.js'; -import { Children, Slot } from '../minimal/client.js'; +import { Children, Slot, ThrowError_UNSTABLE } from '../minimal/client.js'; const hasPathSpecPrefix = (prefix: PathSpec, path: PathSpec) => { for (let i = 0; i < prefix.length; i++) { @@ -832,8 +832,12 @@ export const new_createPages = < Slot, { id: 'root', unstable_renderPrev: true }, layoutPaths.includes('/') - ? createElement(Slot, { id: 'layout:/', unstable_renderPrev: true }) - : null, + ? createElement( + Slot, + { id: 'layout:/', unstable_renderPrev: true }, + createElement(ThrowError_UNSTABLE), + ) + : createElement(ThrowError_UNSTABLE), ), }; },