oxc-project/oxc · error · OxcDiagnostic
Prefer `.textContent` over `.innerText`.
Error message
Prefer `.textContent` over `.innerText`.
What it means
Diagnostic from the unicorn/prefer-dom-node-text-content lint rule. It fires when `.innerText` is read or written on a DOM node. `innerText` is layout-aware (it triggers reflow and is not part of the DOM standard), while `textContent` returns all contained text cheaply and is the standard property. It is a performance/style suggestion, not a runtime error.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/prefer_dom_node_text_content.rs:9
use oxc_ast::{AstKind, ast::PropertyKey};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule};
fn prefer_dom_node_text_content_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer `.textContent` over `.innerText`.")
.with_help("Replace `.innerText` with `.textContent`.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct PreferDomNodeTextContent;
declare_oxc_lint!(
/// ### What it does
///
/// Enforces the use of `.textContent` over `.innerText` for DOM nodes.
///
/// ### Why is this bad?
///
/// There are some disadvantages of using `.innerText`.
/// - `.innerText` returns rendered text and ignores hidden content, while `.textContent` returns the node's full text content.
/// - `.innerText` can trigger reflow because it takes CSS styles into account.
/// - `.innerText` is defined only for HTMLElement objects, while `.textContent` is defined for all Node objects.View on GitHub (pinned to e1e7af627c)
Solutions
- Replace `.innerText` with `.textContent`
- Use `textContent` when the rendered/CSS-aware semantics of `innerText` are not required
- Apply the rule's auto-fix
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/prefer_dom_node_text_content.rs:9 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/60fbd48d97c7588e.
Report an issue: GitHub.