Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit a5b0087

Browse files
author
Je
committed
fix: fix useDeno deadloop in ssg
1 parent 6d7c760 commit a5b0087

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export function useDeno<T = any>(callback: () => (T | Promise<T>), browser?: boo
1313
const { pathname, query } = useRouter()
1414
const [data, setDate] = useState(() => {
1515
const global = window as any
16-
const { _useDenoAsyncData: asyncData } = global
1716
const useDenoUrl = `useDeno://${pathname}?${query.toString()}`
17+
const { [`__asyncData_${useDenoUrl}`]: asyncData } = global
1818
const key = `${useDenoUrl}#${id}`
1919
if (asyncData && key in asyncData) {
2020
return asyncData[key]

renderer.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,14 @@ export async function renderPage(
4848
const data: Record<string, any> = {}
4949
const useDenEvent = `useDeno://${url.pathname + '?' + url.query.toString()}`
5050
const useDenoAsyncCalls: Array<Promise<any>> = []
51-
const orginFetch = window.fetch
5251
events.on(useDenEvent, (id: string, ret: any, async: boolean) => {
5352
if (async) {
5453
useDenoAsyncCalls.push(ret)
5554
} else {
5655
data[id] = ret
5756
}
5857
})
59-
Object.assign(window, {
60-
_useDenoAsyncData: {},
61-
fetch: (input: Request | URL | string, init?: RequestInit) => {
62-
console.log(`[ renderer ] fetch '${input}' ...`)
63-
return orginFetch(input, init)
64-
}
65-
})
58+
Object.assign(window, { [`__asyncData_${useDenEvent}`]: {} })
6659
while (true) {
6760
try {
6861
if (useDenoAsyncCalls.length > 0) {
@@ -82,11 +75,12 @@ export async function renderPage(
8275
if (error instanceof AsyncUseDenoError) {
8376
continue
8477
}
85-
Object.assign(window, { _useDenoAsyncData: null, fetch: orginFetch })
78+
console.log(error)
79+
Object.assign(window, { [`__asyncData_${useDenEvent}`]: null })
8680
throw error
8781
}
8882
}
89-
Object.assign(window, { _useDenoAsyncData: null, fetch: orginFetch })
83+
Object.assign(window, { [`__asyncData_${useDenEvent}`]: null })
9084
events.removeAllListeners(useDenEvent)
9185
return [html, Object.keys(data).length > 0 ? data : null]
9286
}

0 commit comments

Comments
 (0)