Issue 1:
When bundling code that uses the renderToString method, multiple versions of react-dom are included in the bundle.

import { renderToString } from 'react-dom/server';

This is the visualised breakdown of the code included in a bundle assembled with esbuild with the following options (it is bundled up for use in a server rather than client):

{
plugins: [pnpPlugin()],
bundle: true,
entryPoints: [`${routesDir}/${config.relativeFilePath}`],
external: [
'aws-sdk', // included in Lambda runtime environment
],
minify: true,
platform: 'node',
format: 'cjs',
target: 'node16.0',
treeShaking: true,
sourcemap: true,
outfile: getOutFileForLambda(config),
metafile: true,
}

Note here the following files are included:

react-dom-server-legacy.node.production.min.js

react-dom-server.node.production.min.js

react-dom-server.node.development.js

react-dom-server-legacy.node.development.js

react-dom.production.min.js

react-dom.development.js

I would assume only two of these should be required (one for react-dom and one for react-dom-server).

Note I carefully cleaned the dependency tree of the project to ensure there is only one version of react and react-dom referenced.

The workspace this was tested in was created using Yarn 3.

React version: 18.2.0

Steps To Reproduce

Create a file render.ts that contains a call to the renderToString method.

import type React from 'react';
import { renderToString } from 'react-dom/server';

renderToString(<div>Hi</div>);

Provide this file as the entrypoint to bundle it with esbuild

esbuild render.ts --bundle --metafile=meta.json --platform=node

Visualise meta.json with esbuild-visualizer

esbuild-visualizer --metadata ./meta.json

The current behavior

When using the renderToString method in a file that is bundled, the following files are included in the bundle.

react-dom-server-legacy.node.production.min.js

react-dom-server.node.production.min.js

react-dom-server.node.development.js

react-dom-server-legacy.node.development.js

react-dom.production.min.js

react-dom.development.js

The expected behavior

Only one instance of react-dom and react-dom-server should be included in the bundle.

Note there is some reference to a legacy dom server in react/server.node.js which maybe causing this issue:

https://github.com/facebook/react/blob/main/packages/react-dom/server.node.js#L15

Issue 2:
Using destructuring assignment on objects falsely triggers use-exhaustive-deps. For example, I would expect the following not to trigger lint rule:

const object = { hello: 'world', foo: 'bar' }

useEffect(() => {
const { hello } = object
console.log(hello)
}, [object.hello])

The linter insists I pass object to the dependency array which is problematic since objects are compared by reference instead of value. I could destructure out of the useEffect block but this can cause naming collisions for bigger components/hooks. I can also assign variables the old fashioned way but that conflicts with our coding style.

The linting rule also has trouble with safety operator:

const object = { hello: 'world', foo: 'bar' }

useEffect(() => {
const hello = object?.hello
console.log(hello)
}, [object.hello])

will cause it to ask for object in the dependency array.