( opts: SerializeDocumentOptions, resolvedManifest: ResolvedManifest | undefined )
| 10 | const SYNC_QRL = '<sync>'; |
| 11 | |
| 12 | export function createPlatform( |
| 13 | opts: SerializeDocumentOptions, |
| 14 | resolvedManifest: ResolvedManifest | undefined |
| 15 | ) { |
| 16 | const mapper = resolvedManifest?.mapper; |
| 17 | const mapperFn = opts.symbolMapper |
| 18 | ? opts.symbolMapper |
| 19 | : (symbolName: string, _chunk: any, parent?: string): readonly [string, string] | undefined => { |
| 20 | if (mapper) { |
| 21 | const hash = getSymbolHash(symbolName); |
| 22 | const result = mapper[hash]; |
| 23 | if (!result) { |
| 24 | if (hash === SYNC_QRL) { |
| 25 | return [hash, ''] as const; |
| 26 | } |
| 27 | const isRegistered = (globalThis as any).__qwik_reg_symbols?.has(hash); |
| 28 | if (isRegistered) { |
| 29 | return [symbolName, '_'] as const; |
| 30 | } |
| 31 | if (parent) { |
| 32 | // In dev mode, SSR may need to refer to a symbol that wasn't built yet on the client |
| 33 | return [symbolName, `${parent}?qrl=${symbolName}`] as const; |
| 34 | } |
| 35 | console.error('Cannot resolve symbol', symbolName, 'in', mapper, parent); |
| 36 | } |
| 37 | return result; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | const serverPlatform: CorePlatformServer = { |
| 42 | isServer: true, |
| 43 | async importSymbol(_containerEl, url, symbolName) { |
| 44 | const hash = getSymbolHash(symbolName); |
| 45 | const regSym = (globalThis as any).__qwik_reg_symbols?.get(hash); |
| 46 | if (regSym) { |
| 47 | return regSym; |
| 48 | } |
| 49 | // we never lazy import on the server |
| 50 | throw qError(QError_dynamicImportFailed, symbolName); |
| 51 | }, |
| 52 | raf: () => { |
| 53 | console.error('server can not rerender'); |
| 54 | return Promise.resolve(); |
| 55 | }, |
| 56 | nextTick: (fn) => { |
| 57 | return new Promise((resolve) => { |
| 58 | // Do not use process.nextTick, as this will execute at same priority as promises. |
| 59 | // We need to execute after promises. |
| 60 | setTimeout(() => { |
| 61 | resolve(fn()); |
| 62 | }); |
| 63 | }); |
| 64 | }, |
| 65 | chunkForSymbol(symbolName: string, _chunk, parent) { |
| 66 | return mapperFn(symbolName, mapper, parent); |
| 67 | }, |
| 68 | }; |
| 69 | return serverPlatform; |
no test coverage detected
searching dependent graphs…