Skip to content

React Intl codemod can drop a custom provider’s SSR stylesheet initialization #2444

Closed

Description

@domgan-oai

The React Intl codemod accepts a component-owned useIntl().locale read. It preserves the formatter object, but the read itself moves into Octane's render. A custom RawIntlProvider value can implement locale as an ordinary accessor and perform React DOM resource work during that read.

A minimal consumer is:

import { useIntl } from 'react-intl';

export function Leaf() {
  const locale = useIntl().locale;
  return <b>{locale}</b>;
}

Give the original and generated providers the same value:

import { preinit } from 'react-dom';
import { createIntl } from 'react-intl';

const value = createIntl({ locale: 'fr' });
Object.defineProperty(value, 'locale', {
  enumerable: true,
  get() {
    preinit('/locale.css', { as: 'style' });
    return 'fr';
  },
});

The codemod reports Strong with no errors. React SSR emits the stylesheet link and renders <b>fr</b>. Native SSR renders the same text but omits the stylesheet from both the head and HTML. Each renderer reads the property once. An unmodified createIntl value is a matching control. React DOM documents resource initialization during server rendering. React DOM preinit

Expected. Preserve the resource initialization or retain a binding diagnostic when the original provider can perform renderer-owned work. An exported component's read syntax alone cannot establish which provider owns its value. Draft #2442 exposes the same boundary for a destructured locale.

Reproduction

Verified with the codemod at upstream 597eecc4165954598d4cfaa9709725251ff0554f, production mode, Node 26.12.1, installed Octane 0.16.7, React and React DOM 19.2.7, and React Intl 7.1.14. Use a separate Octane checkout at that commit, install the workspace, and build the codemod. Save the script below as repro.mjs outside the checkout.

repo=/path/to/octane
fixture=$(mktemp -d)
(cd "$repo" && pnpm install --frozen-lockfile && pnpm --filter @octanejs/codemod build)
(cd "$fixture" && npm init -y && npm install --save-exact [email protected] [email protected] [email protected] [email protected])
NODE_ENV=production node /path/to/repro.mjs "$repo" "$fixture/node_modules"

The final assertion fails because the native output has no stylesheet link.

Standalone repro.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { createRequire } from 'node:module';
import os from 'node:os';
import path from 'node:path';
import { pathToFileURL } from 'node:url';

const repo = path.resolve(process.argv[2] || '.');
const dependencies = path.resolve(process.argv[3] || 'node_modules');
const tools = createRequire(path.join(repo, 'package.json'));
const { build } = tools('esbuild');
const { runCodemod } = await import(
  pathToFileURL(path.join(repo, 'packages/codemod/dist/index.js'))
);
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'intl-provider-repro-'));
const write = (file, text) => fs.writeFileSync(path.join(root, file), text);

try {
  fs.mkdirSync(path.join(root, 'node_modules'));
  const packages = {};
  for (const name of ['octane', 'react', 'react-dom', 'react-intl']) {
    const installed = fs.realpathSync(path.join(dependencies, name));
    fs.symlinkSync(installed, path.join(root, 'node_modules', name), 'dir');
    packages[name] = JSON.parse(fs.readFileSync(path.join(installed, 'package.json'))).version;
  }
  write('package.json', JSON.stringify({ name: 'intl-provider-repro', type: 'module', dependencies: packages }));
  write('tsconfig.json', JSON.stringify({ compilerOptions: { module: 'ESNext', moduleResolution: 'Bundler', jsx: 'react-jsx' } }));
  const input = `import {useIntl} from 'react-intl';
export function Leaf(){const locale = useIntl().locale; return <b>{locale}</b>}`;
  write('Original.tsx', input);
  write('Leaf.tsx', input);
  const result = await runCodemod([path.join(root, 'Leaf.tsx')], {
    root, write: true, projectTypes: true, verify: true, strong: true
  });
  const file = result.files.find(f => f.file === 'Leaf.tsx');
  const errors = [...file.notes, ...file.diagnostics].filter(d => d.severity === 'error');
  console.log(JSON.stringify({ packages, strong: file.strong, errors }));
  if (!errors.length) {
    write('Native.tsrx', `import {RawIntlProvider} from './octane-react-intl.tsrx';
import {Leaf} from './Leaf.tsrx';
export function Native({value}) {return <RawIntlProvider value={value}><Leaf/></RawIntlProvider>}`);
    const require = createRequire(path.join(root, 'package.json'));
    const { compile } = await import(pathToFileURL(require.resolve('octane/compiler')));
    const outfile = path.join(root, 'server.mjs');
    await build({
      stdin: {resolveDir: root, contents: `export {Leaf} from './Original.tsx';
export {Native} from './Native.tsrx';
export {renderToString} from 'octane/server';`},
      outfile, bundle: true, format: 'esm', platform: 'node', jsx: 'automatic',
      external: ['react', 'react-dom', 'react-dom/*', 'react-intl'],
      plugins: [{ name: 'tsrx', setup(b) {
        b.onLoad({filter: /\.tsrx$/}, ({path: file}) => ({
          contents: compile(fs.readFileSync(file, 'utf8'), file, { mode: 'server' }).code,
          loader: 'js',
          resolveDir: path.dirname(file),
        }));
      }}],
    });
    const { Leaf, Native, renderToString } = await import(pathToFileURL(outfile));
    const { createElement } = require('react');
    const { renderToStaticMarkup } = require('react-dom/server');
    const { preinit } = require('react-dom');
    const { createIntl, RawIntlProvider } = require('react-intl');

    const render = (value) => {
      const react = renderToStaticMarkup(createElement(RawIntlProvider, { value }, createElement(Leaf)));
      const native = renderToString(Native, { value });
      return { react, native: (native.head ?? '') + native.html };
    };
    const control = render(createIntl({ locale: 'fr' }));
    assert.equal(control.react, '<b>fr</b>');
    assert.match(control.native, /<b>fr<\/b>/);
    let reads = 0;
    const value = createIntl({ locale: 'fr' });
    Object.defineProperty(value, 'locale', {
      enumerable: true,
      get() {
        reads++;
        preinit('/locale.css', { as: 'style' });
        return 'fr';
      },
    });
    const observed = render(value);
    assert.equal(reads, 2);
    console.log(JSON.stringify({ ...observed, reads }));
    assert.match(observed.react, /href="\/locale.css"/);
    assert.match(observed.native, /href="\/locale.css"/);
  }
} finally {
  fs.rmSync(root, { recursive: true, force: true });
}

Activity

  1. added
    bug
    agent-authored
    on Nov 11, 2026
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

    agent-authoredbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions