Skip to content

Bug: ReactDOM.preloadModule crashes with repeated custom as value #36440

@afurm

Description

@afurm

React version: current main (d5736f098edee62c44f27b053e6e48f5fa443803 locally)

Steps To Reproduce

  1. Render a component on the server with two ReactDOM.preloadModule() calls that use the same non-default as value:
function App() {
  ReactDOM.preloadModule('worker-a', {as: 'serviceworker'});
  ReactDOM.preloadModule('worker-b', {as: 'serviceworker'});
  return <div>hello</div>;
}

renderToPipeableStream(<App />).pipe(writable);
  1. Let the Fizz render run.

Link to code example: minimal reproduction above; this is also covered by the added regression test in packages/react-dom/src/__tests__/ReactDOMFloat-test.js.

The current behavior

The second call crashes during server rendering:

TypeError: Cannot read properties of undefined (reading 'hasOwnProperty')

The repeated custom-as path checks moduleUnknownResources but then reads the bucket from unknownResources, so the bucket can be undefined.

The expected behavior

Fizz should track repeated custom module preload as values in moduleUnknownResources and emit both module preload links without crashing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions