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
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ export class ProgramContext {
);
}

removeMemoCacheImport(): void {
const moduleImports = this.imports.get(this.reactRuntimeModule);
if (moduleImports == null) {
return;
}
moduleImports.delete('c');
if (moduleImports.size === 0) {
this.imports.delete(this.reactRuntimeModule);
}
}

/**
*
* @param externalFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,13 @@ function applyCompiledFunctions(

// Forget compiled the component, we need to update existing imports of useMemoCache
if (compiledFns.length > 0) {
// Codegen may have registered `_c` for a function that was later discarded.
const anyAppliedUsesMemo = compiledFns.some(
result => result.compiledFn.memoSlotsUsed > 0,
);
if (!anyAppliedUsesMemo) {
programContext.removeMemoCacheImport();
}
addImportsToProgram(program, programContext);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const FIXTURE_ENTRYPOINT = {
## Code

```javascript
import { c as _c } from "react/compiler-runtime";
import { useRef } from "react";

const useControllableState = (options) => {};
Expand Down
Loading