vite-plugin-react-server
Version:
Vite plugin for React Server Components (RSC)
29 lines (28 loc) • 964 B
JavaScript
import { getModuleRef } from "../../helpers/moduleRefs.js";
// Track active RSC streams
export const activeStreams = new Map();
// Track module IDs
export const moduleIds = new Map();
// Track resolved components cache using Map for better memory management
export const temporaryReferences = new WeakMap();
export function addModuleId(id, url) {
moduleIds.set(id, url);
}
// Helper to cache a resolved component
export function cacheComponent(id, component) {
const moduleRef = getModuleRef(id);
temporaryReferences.set(moduleRef, component);
}
// Helper to get a cached component
export function getCachedComponent(id) {
const moduleRef = getModuleRef(id);
return temporaryReferences.get(moduleRef);
}
// Helper to check if a component is cached
export function hasCachedComponent(id) {
const moduleRef = getModuleRef(id);
return temporaryReferences.has(moduleRef);
}
export function getModuleId(id) {
return moduleIds.get(id);
}