diff --git a/editor/src/core/workers/parser-printer/parse-cache-utils.worker.ts b/editor/src/core/workers/parser-printer/parse-cache-utils.worker.ts index 463be361a299..7687e09f1cc3 100644 --- a/editor/src/core/workers/parser-printer/parse-cache-utils.worker.ts +++ b/editor/src/core/workers/parser-printer/parse-cache-utils.worker.ts @@ -3,10 +3,12 @@ import { URL_HASH } from '../../../common/env-vars' import { type ParseCacheOptions } from '../../../core/shared/parse-cache-utils' import { ARBITRARY_CODE_FILE_NAME, + createParseFileResult, type ParseFile, type ParseFileResult, } from '../common/worker-types' import localforage from 'localforage' +import type { ParsedTextFile } from 'utopia-shared/src/types' export const CACHE_DB_NAME = 'editor-cache' export const PARSE_CACHE_STORE_NAME = 'file-parse-cache' @@ -66,7 +68,7 @@ export async function getParseResultFromCache( file: ParseFile, parsingCacheOptions: ParseCacheOptions, ): Promise { - const { filename, content } = file + const { filename, content, versionNumber } = file if (!shouldUseCacheForFile(filename, parsingCacheOptions)) { return null } @@ -74,9 +76,9 @@ export async function getParseResultFromCache( //check localforage for cache const cachedResult = await getParseCacheStore().getItem(cacheKey) const cachedResultForContent = cachedResult?.[getCacheIndexKeyWithVersion(content)] - if (cachedResultForContent?.parseResult?.type === 'PARSE_SUCCESS') { + if (cachedResultForContent?.type === 'PARSE_SUCCESS') { logCacheMessage(parsingCacheOptions, 'Cache hit for', ...stringIdentifiers(filename, content)) - return cachedResultForContent + return createParseFileResult(filename, cachedResultForContent, versionNumber) } logCacheMessage(parsingCacheOptions, 'Cache miss for', ...stringIdentifiers(filename, content)) return null @@ -84,7 +86,7 @@ export async function getParseResultFromCache( export async function storeParseResultInCache( file: ParseFile, - result: ParseFileResult, + result: ParsedTextFile, parsingCacheOptions: ParseCacheOptions, ): Promise { const { filename, content } = file @@ -121,4 +123,4 @@ export async function clearParseCache(parsingCacheOptions: ParseCacheOptions) { }) } -type CachedParseResult = { [fileContent: string]: ParseFileResult } +type CachedParseResult = { [fileContent: string]: ParsedTextFile } diff --git a/editor/src/core/workers/parser-printer/parser-printer-worker.ts b/editor/src/core/workers/parser-printer/parser-printer-worker.ts index e89289472261..9de424eb7f26 100644 --- a/editor/src/core/workers/parser-printer/parser-printer-worker.ts +++ b/editor/src/core/workers/parser-printer/parser-printer-worker.ts @@ -104,7 +104,7 @@ export function getParseFileResult( parseOptions.parsingCacheOptions.useParsingCache ) { // non blocking cache write - void storeParseResultInCache(file, result, parseOptions.parsingCacheOptions) + void storeParseResultInCache(file, result.parseResult, parseOptions.parsingCacheOptions) } return result