| 18 | |
| 19 | const withAssets = function <T extends () => Promise<{ default: Component<any> }>>(fn: T): T { |
| 20 | const wrapper = async () => { |
| 21 | const mod = await fn(); |
| 22 | |
| 23 | // This id$$ export is generated by the lazy vite plugin |
| 24 | const id: string = (mod as any).id$$; |
| 25 | if (!id) return mod; |
| 26 | |
| 27 | if (!mod.default) { |
| 28 | console.error(`Module ${id} does not export default`); |
| 29 | return { default: () => [] }; |
| 30 | } |
| 31 | |
| 32 | const assets: Asset[] = await getAssets(id); |
| 33 | if (!assets.length) return mod; |
| 34 | |
| 35 | return { |
| 36 | default: (props: any) => { |
| 37 | const { nonce } = getRequestEvent() as PageEvent; |
| 38 | useAssets(assets, nonce); |
| 39 | |
| 40 | return mod.default(props); |
| 41 | }, |
| 42 | }; |
| 43 | }; |
| 44 | |
| 45 | return wrapper as T; |
| 46 | }; |