oxc-project/oxc · error · OxcDiagnostic

Standard form for React fragments is preferred.

Error message

Standard form for React fragments is preferred.

What it means

Raised by react/jsx_fragments when the rule is configured to prefer the element form (`FragmentMode::Element`) and shorthand fragment syntax `<></>` is encountered. At the throw site the fragment could not carry a `key` prop and the project style mandates explicit `<React.Fragment>` elements. jsx_fragments_diagnostic selects this message/help pair based on the configured mode and is called from run() on each JSX fragment node.

Source

Thrown at crates/oxc_linter/src/rules/react/jsx_fragments.rs:27

use crate::{
    AstNode,
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
    utils::is_jsx_fragment,
};

fn jsx_fragments_diagnostic(span: Span, mode: FragmentMode) -> OxcDiagnostic {
    let msg = if mode == FragmentMode::Element {
        "Standard form for React fragments is preferred."
    } else {
        "Shorthand form for React fragments is preferred."
    };
    let help = if mode == FragmentMode::Element {
        "Use `<React.Fragment></React.Fragment>` instead of `<></>`."
    } else {
        "Use `<></>` instead of `<React.Fragment></React.Fragment>`."
    };
    OxcDiagnostic::warn(msg).with_help(help).with_label(span)
}

// Generally we should prefer the string-only syntax for compatibility with the original ESLint rule,
// but we originally implemented the rule with only the object syntax, so we support both now.
#[derive(Debug, Clone, JsonSchema, Deserialize)]
#[serde(untagged)]
pub enum JsxFragments {
    Mode(FragmentMode),
    Object { mode: FragmentMode },
}

impl Default for JsxFragments {
    fn default() -> Self {
        JsxFragments::Mode(FragmentMode::Syntax)
    }
}

impl JsxFragments {

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace <></> with <React.Fragment></React.Fragment>.
  2. Switch the rule mode to 'syntax' if shorthand is preferred.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/react/jsx_fragments.rs:27 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/cb23b61fcb5f1061. Report an issue: GitHub.