Skip to content

codemod: preserve React DOM resource effects from opaque dependency getters #2448

Closed

Description

@domgan-oai

Reproduction

Run the public codemod with Strong mode, project types, and compiler verification on this React component, then compile the output in server mode.

import { useEffect, useEffectEvent } from 'react'

export function List({ probe }: { probe: { value: number } }) {
  const work = useEffectEvent(() => {})
  useEffect(() => { return work() }, [probe.value])
  return <b>ok</b>
}

Render the original with React DOM server and the migrated component with standalone Octane SSR. Pass a fresh instance of these props to each renderer.

import { preinit } from 'react-dom'

const props = {
  probe: {
    get value() {
      preinit('/snapshot.css', { as: 'style' })
      return 1
    },
  },
}

Observed

React emits a stylesheet link for /snapshot.css and <b>ok</b>. The migrated component emits <b>ok</b> without the link. The result reproduces in development and production on Octane 0.16.7 and React and React DOM 19.2.7.

The same difference occurs on main at 731927750, where the codemod retains the explicit dependency in compatibility mode, and in the proposed Strong migration that captures the getter at the original render site.

Expected

The migration should preserve the getter's renderer-owned resource effect or surface a diagnostic when it cannot establish that effect's ownership. The getter executes during server rendering, where React supports this use of preinit. React DOM API reference

Activity

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