Fix Metro bundler refresh issue by preventing unnecessary file writes
- Only write auto-generated.d.ts when actual content changes - Strip timestamp lines when comparing content to detect real changes - Prevents Metro from refreshing when type content is unchanged - Fixes flickering "Refreshing..." issue across all connected devices 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -253,13 +253,13 @@ async function updateGlobalTypes() {
|
||||
const projectRoot = process.cwd();
|
||||
const typesDir = path.join(projectRoot, 'src', 'types');
|
||||
const globalTypesPath = path.join(typesDir, 'auto-generated.d.ts');
|
||||
|
||||
|
||||
let content = '/**\n';
|
||||
content += ' * Auto-generated type declarations for remote IOR components\n';
|
||||
content += ` * Generated at: ${new Date().toISOString()}\n`;
|
||||
content += ' * DO NOT EDIT - This file is automatically maintained by metro-ior-resolver\n';
|
||||
content += ' */\n\n';
|
||||
|
||||
|
||||
// Add all cached type definitions
|
||||
for (const [ior, entry] of typeCache.entries()) {
|
||||
content += `// Source: ${entry.source || 'unknown'}`;
|
||||
@@ -272,16 +272,31 @@ async function updateGlobalTypes() {
|
||||
content += entry.content;
|
||||
content += '\n\n';
|
||||
}
|
||||
|
||||
|
||||
// Ensure directory exists
|
||||
if (!fs.existsSync(typesDir)) {
|
||||
fs.mkdirSync(typesDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Write the file
|
||||
fs.writeFileSync(globalTypesPath, content, 'utf-8');
|
||||
|
||||
console.log(`[IOR Resolver] Updated auto-generated types: ${globalTypesPath}`);
|
||||
|
||||
// Only write if content has changed (compare without timestamp)
|
||||
let shouldWrite = true;
|
||||
if (fs.existsSync(globalTypesPath)) {
|
||||
const existingContent = fs.readFileSync(globalTypesPath, 'utf-8');
|
||||
|
||||
// Remove timestamp lines for comparison
|
||||
const stripTimestamp = (str) => str.replace(/ \* Generated at: .*\n/g, '').replace(/\/\/ Cached: .*\n/g, '');
|
||||
|
||||
if (stripTimestamp(existingContent) === stripTimestamp(content)) {
|
||||
shouldWrite = false;
|
||||
console.log(`[IOR Resolver] Type declarations unchanged, skipping write to prevent Metro refresh`);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldWrite) {
|
||||
// Write the file
|
||||
fs.writeFileSync(globalTypesPath, content, 'utf-8');
|
||||
console.log(`[IOR Resolver] Updated auto-generated types: ${globalTypesPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user