Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/app/src/sandbox/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ function overrideDocumentClose() {
overrideDocumentClose();

interface CompileOptions {
sandboxId: string;
sandboxId?: string | null;
modules: { [path: string]: Module };
customNpmRegistries?: NpmRegistry[];
externalResources: string[];
Expand Down Expand Up @@ -777,13 +777,7 @@ async function compile(opts: CompileOptions) {
type: 'success',
});

saveCache(
sandboxId,
managerModuleToTranspile,
manager,
changedModuleCount,
firstLoad
);
saveCache(managerModuleToTranspile, manager, changedModuleCount, firstLoad);

setTimeout(async () => {
try {
Expand Down
9 changes: 6 additions & 3 deletions packages/sandpack-core/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ export function clearIndexedDBCache() {
}

export async function saveCache(
sandboxId: string,
managerModuleToTranspile: any,
manager: Manager,
changes: number,
firstRun: boolean
) {
if (!sandboxId) {
if (!manager.id) {
return Promise.resolve(false);
}

Expand Down Expand Up @@ -101,7 +100,7 @@ export async function saveCache(
);

return window
.fetch(`${host}/api/v1/sandboxes/${sandboxId}/cache`, {
.fetch(`${host}/api/v1/sandboxes/${manager.id}/cache`, {
method: 'POST',
body: JSON.stringify({
version: manager.version,
Expand Down Expand Up @@ -188,6 +187,10 @@ export function ignoreNextCache() {
}

export async function consumeCache(manager: Manager) {
if (!manager.id) {
return false;
}

try {
const shouldIgnoreCache =
localStorage.getItem('ignoreCache') ||
Expand Down
7 changes: 5 additions & 2 deletions packages/sandpack-core/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function triggerFileWatch(path: string, type: 'rename' | 'change') {
}
}
export default class Manager implements IEvaluator {
id: string;
id?: string | null;
transpiledModules: {
[path: string]: {
module: Module;
Expand Down Expand Up @@ -179,7 +179,7 @@ export default class Manager implements IEvaluator {
esmodules: Map<string, Promise<string>>;

constructor(
id: string,
id: string | null | undefined,
preset: Preset,
modules: { [path: string]: Module },
options: TManagerOptions,
Expand Down Expand Up @@ -1457,6 +1457,9 @@ export default class Manager implements IEvaluator {

deleteAPICache() {
ignoreNextCache();
if (!this.id) {
return Promise.resolve();
}
return deleteAPICache(this.id, this.version);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export type LoaderContext = {
// Remaining loaders after current loader
remainingRequests: string;
template: string;
sandboxId: string | null;
sandboxId?: string | null;
resourceQuery: string;
getLoaderQuery: (module: Module) => string;
};
Expand Down