mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
dec0a86412
Standardize React Compiler diagnostics with concise titles, primary labels, actionable help, notes, structured categories, and official guidance links. Preserve React guidance when diagnostics are surfaced through Oxlint, and refresh affected snapshots. AI-assisted; reviewed and validated by the contributor.
35 lines
1.4 KiB
Plaintext
35 lines
1.4 KiB
Plaintext
---
|
|
source: crates/oxc_react_compiler/tests/snapshot.rs
|
|
input_file: crates/oxc_react_compiler/fixtures/allow-ref-lazy-initialization-with-logical.js
|
|
---
|
|
Diagnostics:
|
|
|
|
OxcDiagnostic { inner: OxcDiagnosticInner { message: "Cannot access refs during render", labels: [LabeledSpan { label: Some("Cannot access ref value during render"), span: Span { start: 458, end: 469 }, primary: true }], help: Some("React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected"), note: Some("React Compiler skipped optimizing this component or hook"), severity: Error, code: OxcCode { scope: Some("react-compiler"), number: Some("Refs") }, url: Some("https://react.dev/reference/eslint-plugin-react-hooks/lints/refs") } }
|
|
|
|
import { c as _c } from "react/compiler-runtime";
|
|
// @validateRefAccessDuringRender
|
|
import { useRef } from "react";
|
|
function Component(props) {
|
|
const $ = _c(1);
|
|
const ref = useRef(null);
|
|
if (ref.current == null) {
|
|
ref.current = props.unknownKey ?? props.value;
|
|
}
|
|
let t0;
|
|
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
t0 = <Child ref={ref} />;
|
|
$[0] = t0;
|
|
} else {
|
|
t0 = $[0];
|
|
}
|
|
return t0;
|
|
}
|
|
function Child({ ref }) {
|
|
"use no memo";
|
|
return ref.current;
|
|
}
|
|
export const FIXTURE_ENTRYPOINT = {
|
|
fn: Component,
|
|
params: [{ value: 42 }]
|
|
};
|