Skip to content

components created unnecessarily #80

Open

Description

@derekrjones

in the following example, when refreshed, CompB is created more times than it should

// ex. App.tsx has single <CompA/>
export const function CompA() {
  console.log('A');
  return <CompB />;
}
function CompB() {
  console.log('B');
  return <div>hi</div>;
}

initial run logs A B
file save, logs B A B (or A B B if CompB initially placed above CompA)

If CompB was costly, then this would have an impact of perf.

Activity

  1. derekrjones commented on Oct 4, 2025

    @derekrjones
    Author

    Would using batch() in patchRegistry be a solution? (batch patchContexts and patchComponents)

    function patchRegistry(oldRegistry: Registry, newRegistry: Registry) {
    const shouldInvalidateByContext = patchContexts(oldRegistry, newRegistry);
    const shouldInvalidateByComponents = patchComponents(
    oldRegistry,
    newRegistry,
    );
    // In the future we may add other HMR features here
    return shouldInvalidateByComponents || shouldInvalidateByContext;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions