From 2d2ce2b01797fb020f921a5e8a73ab9a540cd168 Mon Sep 17 00:00:00 2001 From: Romuald Brillout Date: Tue, 20 Aug 2024 15:05:26 +0200 Subject: [PATCH] fix: make useConfig() work for vike-solid hooks --- vike-solid/utils/callCumulativeHooks.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/vike-solid/utils/callCumulativeHooks.ts b/vike-solid/utils/callCumulativeHooks.ts index e4ba0ed..e5b6aca 100644 --- a/vike-solid/utils/callCumulativeHooks.ts +++ b/vike-solid/utils/callCumulativeHooks.ts @@ -1,14 +1,22 @@ -export async function callCumulativeHooks(values: undefined | unknown[], pageContext: unknown): Promise { - if (!values) return []; +export { callCumulativeHooks } + +import { providePageContext } from 'vike/getPageContext' + +async function callCumulativeHooks( + values: undefined | unknown[], + pageContext: Record, +): Promise { + if (!values) return [] const valuesPromises = values.map((val) => { - if (typeof val === "function") { + if (typeof val === 'function') { + providePageContext(pageContext) // Hook - return val(pageContext); + return val(pageContext) } else { // Plain value - return val; + return val } - }); - const valuesResolved = await Promise.all(valuesPromises); - return valuesResolved; + }) + const valuesResolved = await Promise.all(valuesPromises) + return valuesResolved }