oxc-project/oxc · error · OxcDiagnostic

Shorthand form for React fragments is preferred.

Error message

Shorthand form for React fragments is preferred.

What it means

Raised by react/jsx_fragments when the rule is in its default shorthand-preferring mode and an explicit `<React.Fragment>...</React.Fragment>` element is found (without a key, per config). At the throw site the verbose element form deviates from the enforced `<></>` idiom that the project adopted for brevity. jsx_fragments_diagnostic picks this message branch for the shorthand mode and is emitted from run() while traversing JSX elements named Fragment.

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 <React.Fragment></React.Fragment> with <></> (keeping keys via the keyed form when needed).
  2. Switch the rule mode to 'element' if the explicit form 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/87eb74850e243143. Report an issue: GitHub.