Skip to content

Question: Async React Reconciler #32046

Open
@simonedevit

Description

Apologies for using the bug template, but I have a question regarding React Reconciler. I understand that this is not intended for questions, and I appreciate your understanding.

I'm building a custom React reconciler by using react-reconciler package. I'm wondering if it is possible having an async reconciler. I need to dynamic import a module in the createInstance method of HostConfig based on the type parameter. A minimal implementation example could be:

// reconciler.ts
async createInstance(type, props, rootContainer, hostContext, internalHandle){
    const Module = await import(`my-module-path/${type}`);
    const instance = new Module();
    return instance;
}

getPublicInstance(instance){
    return instance; // this is a Promise
}

The main issue is that in this way i'm returning a Promise as ref and then i should handle it in this way:

// Component.tsx
  useEffect(() => {
    ref.current.then((instance) => {
      // access here to instance
    })
  }, [ref])

Mine is not a primary renderer so, as workaround, i thought to traversing the Fiber node (generated by React reconciler) to get the all tag names (JSX intrinsic elements) and then dynamic import them before to start the secondary rendering process (createContainer and updateContainer). Unfortunately this not entirely correct because the root Fiber node does not encompass all components of the tree. For example, in the following scenario, only one between the box and the sphere will be included:

condition ? <box /> : <sphere />

Are there other ways to think about this problem?


React (react package) version: 18.3.1
React reconciler (react-reconciler package): 0.29.2

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions