createRoot method

Future<void> createRoot(
  1. DCFComponentNode component
)

Create the root component for the application

Implementation

Future<void> createRoot(DCFComponentNode component) async {
  if (kDebugMode) {
    print('🌱 Creating root with component: ${component.runtimeType} (key: ${component.key})');
  }

  // If there's already a root component, reconcile instead of just replacing
  if (rootComponent != null) {
    if (kDebugMode) {
      print('🔄 Existing root found, performing reconciliation...');
      print('🔄 Old root: ${rootComponent!.runtimeType} (key: ${rootComponent!.key})');
      print('🔄 New root: ${component.runtimeType} (key: ${component.key})');
    }

    // Perform reconciliation between old and new root
    await _reconcile(rootComponent!, component);

    // Update the root component reference
    rootComponent = component;
  } else {
    // First time creating root
    if (kDebugMode) {
      print('🆕 First time creating root component');
    }
    rootComponent = component;

    // Register the component with this VDOM
    registerComponent(component);

    // Render to native
    await renderToNative(component, parentViewId: "root");
  }

  if (kDebugMode) {
    print('✅ Root creation/update completed');
  }
}