React 19 Plugin Migration

grafana/skills/skills/grafana-plugins/react-19-plugin-migration

作者 grafana1ccacf29049fApache-2.0279 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Migrate a Grafana plugin to React 19 compatibility. Use when the user asks to update a plugin for React 19, prepare for React 19, fix React 19 compatibility, upgrade to React 19, migrate to React 19, bump grafanaDependency to 12.3.0, externalize jsx-runtime, or run react-detect. Triggers on phrases like "update plugin for React 19", "React 19 migration", "prepare for React 19", "plugin React 19 compat", "grafanaDependency 12.3.0", "JSX runtime externals", "react-detect", "SECRET_INTERNALS", "ReactCurrentOwner", or "ReactCurrentDispatcher".

AI 產生的概覽

指導將 Grafana 外掛遷移至 React 19 相容,依序完成建置、相依性與原始碼修改步驟。

功能
提供一套依序執行的十一步流程,讓 Grafana 外掛向前相容於 React 19,而不升級 React 本身。內容涵蓋辨識外掛脈絡、執行 react-detect 掃描、更新 create-plugin 樣板、完成 ESLint 9 扁平設定遷移、將 jsx-runtime 外部化、調升 grafanaDependency 以及 Grafana、Faro、React 相關相依性、修正 peer 相依性,並修正原始碼中已棄用的 React API。最後進行建置、型別檢查與測試驗證、CI 檢查,並壓縮成單一提交,同時指向一份已知問題參考文件。
適用情境
當使用者要求為 React 19 更新 Grafana 外掛、為 React 19 做準備、修正 React 19 相容性、將 grafanaDependency 調升到 12.3.0、將 jsx-runtime 外部化或執行 react-detect 時使用。適用於為 Grafana 13 做準備的外掛儲存庫。
執行需求
需要具備 shell 與 git 存取權限的代理,並在 Grafana 外掛儲存庫中作業。需要 Node.js、npm/npx、yarn 或 pnpm、jq,以及用於取得 @grafana/create-plugin 和 @grafana/react-detect 的網路存取。多個步驟要求 git 工作區乾淨。不附帶指令碼,僅為說明文件,另有一份已知問題參考文件。

Migrate Grafana Plugin to React 19

Grafana 13 (April 2026) moves from React 18 to React 19. Incompatible plugins will break. Do not upgrade React to 19 — only make forward-compatible changes.

All changes go in one PR. Execute steps in order. Never manually edit yarn.lock.


Step 1: Detect plugin context

bash
PLUGIN_JSON=$([ -f src/plugin.json ] && echo "src/plugin.json" \  || ([ -f plugin/src/plugin.json ] && echo "plugin/src/plugin.json" || echo ""))PKG_JSON=$([ -f package.json ] && echo "package.json" \  || ([ -f plugin/package.json ] && echo "plugin/package.json" || echo ""))PLUGIN_ID=$(jq -r '.id' $PLUGIN_JSON 2>/dev/null)[ -f yarn.lock ] && PM="yarn" || ([ -f pnpm-lock.yaml ] && PM="pnpm" || PM="npm")CP_VERSION=$(jq -r '.version' .config/.cprc.json 2>/dev/null)echo "PLUGIN_ID=$PLUGIN_ID  PM=$PM  CP=$CP_VERSION"

If PLUGIN_ID is empty, ask the user for the plugin root path.


Step 2: Scan for compatibility issues

Build the plugin and run the React 19 compatibility scanner:

bash
npm run build 2>&1 | tail -5npx -y @grafana/react-detect@latest 2>&1

Save the output. It flags:

  • jsxRuntimeImport / __SECRET_INTERNALS → Step 4 fixes this
  • defaultProps / propTypes / ReactDOM.render → Step 8 (source fixes)
  • findDOMNode → Step 6 (dependency bump) or Step 8 (source fix)

If the build fails (plugin hasn't been built before), skip this step and run react-detect after Step 9 instead. If output says "No breaking changes detected", still proceed — jsx-runtime externalization and grafanaDependency bump are always required.

Re-run react-detect after Step 9 to confirm all issues are resolved.


Step 3: Update @grafana/create-plugin

The scaffolding update brings in externals extraction, jest mocks, Docker fixes, and webpack improvements needed for React 19. Always do this before add externalize-jsx-runtime.

Requires a clean git working tree. Create a feature branch first if not already on one.

Run the update

bash
npx @grafana/create-plugin@latest update 2>&1

If yarn install fails with "engine is incompatible"

The update runs an intermediate yarn install without --ignore-engines. Complete it manually:

bash
yarn install --ignore-scripts --ignore-engines 2>&1 | tail -10

Commit the intermediate state and re-run:

bash
git add -A && git commit -m "chore: intermediate create-plugin update" --no-verifynpx @grafana/create-plugin@latest update 2>&1

If ESLint 9 migration (004) fails with a parser error

The auto-migration can generate invalid JS on plugins with complex ESLint configs. Do not skip — commit what succeeded, then complete the ESLint 9 migration manually:

bash
git add -A && git commit -m "chore: update create-plugin (ESLint 9 migration manual)" --no-verify

Then follow the "Complete ESLint 9 migration" section below to finish.

After the update

Always run install and verify:

bash
yarn install --ignore-scripts --ignore-engines 2>&1 | tail -10cat .config/.cprc.json

Commit if there are changes:

bash
git add -A && git diff --cached --quiet || git commit -m "chore: update create-plugin scaffolding" --no-verify

Step 3b: Complete ESLint 9 migration

The create-plugin update bumps ESLint to v9, which requires flat config (eslint.config.js) instead of .eslintrc. Whether the auto-migration (004) succeeded, partially succeeded, or failed, you must ensure ESLint works before proceeding.

Check the current state

bash
ls eslint.config.js .eslintrc* .config/.eslintrc* 2>/dev/nullnpx eslint --version 2>&1

Three scenarios:

A) eslint.config.js exists and yarn lint passes — auto-migration succeeded. Proceed.

B) eslint.config.js exists but yarn lint fails — partial migration. Fix the issues:

bash
yarn lint 2>&1 | head -30

Common fixes:

  • Invalid option '--ignore-path' or Invalid option '--ext' → remove those flags from the lint script in package.json. In ESLint v9 flat config, ignores and file matching are configured inside eslint.config.js, not via CLI flags. Update to: eslint --cache .
  • Cannot find module 'eslint-plugin-deprecation' → remove the import/reference from eslint.config.js (replaced by @typescript-eslint/no-deprecated)
  • Other dead plugin imports → remove them from the config if the package was removed

C) No eslint.config.js exists — auto-migration failed. Create one manually:

bash
ls node_modules/@grafana/eslint-config/flat.js 2>/dev/null

If flat.js exists, create eslint.config.js using it as the base:

js
import grafanaConfig from '@grafana/eslint-config/flat';
export default [  ...grafanaConfig,  {    ignores: ['**/dist/', '**/node_modules/', '**/.config/', '**/coverage/'],  },];

Then migrate any custom rules from the old .eslintrc into additional config objects in the array. After creating the flat config:

  1. Update the lint script: "lint": "eslint --cache ."
  2. Delete the root .eslintrc (leave .config/.eslintrc — it's scaffolded and harmless)

Verify lint works

bash
yarn lint 2>&1 | tail -20

Fix auto-fixable issues with yarn lint --fix. Commit:

bash
git add -A && git diff --cached --quiet || git commit -m "chore: complete ESLint 9 flat config migration" --no-verify

Step 4: Externalize jsx-runtime

Always use the create-plugin add command. Requires a clean git working tree.

bash
npx @grafana/create-plugin@latest add externalize-jsx-runtime 2>&1

Verify:

bash
grep "jsx-runtime" .config/bundler/externals.ts 2>/dev/null
  • Found → commit and proceed.
  • Not found → command failed. Only then add externals manually to the root webpack.config.ts:
ts
externals: ['react/jsx-runtime', 'react/jsx-dev-runtime'],

Commit:

bash
git add -A && git diff --cached --quiet || git commit -m "feat: externalize jsx-runtime" --no-verify

Step 5: Bump grafanaDependency

bash
jq -r '.dependencies.grafanaDependency' $PLUGIN_JSON

If not already >=12.3.0, update it. The create-plugin add in Step 3 may have already done this.


Step 6: Bump dependencies

Faro (if present)

bash
grep '"@grafana/faro' $PKG_JSON
PackageTarget
@grafana/faro-react^2.2.3
@grafana/faro-web-sdk^2.2.3
@grafana/faro-web-tracing^2.0.0

Grafana packages

bash
grep '"@grafana/' $PKG_JSON | grep -v faro | grep -v create-plugin

Bump @grafana/data, @grafana/runtime, @grafana/schema, @grafana/ui to ^12.2.0 or later. Add @grafana/i18n@^12.2.0 if the plugin uses translations or @grafana/scenes requires it.

React types

Bump react and react-dom to ^18.3.0 (surfaces React 19 issues early). Add @types/react@^18.3.0 and @types/react-dom@^18.3.0 to devDependencies if missing.

Remove deprecated packages

Remove from devDependencies if present:

  • eslint-plugin-deprecation (replaced by @typescript-eslint/no-deprecated)
  • @types/testing-library__jest-dom (replaced by setupTests.d.ts)

Broken transitive dependencies

If yarn install fails with a stale git reference, do not edit yarn.lock. Add a resolutions entry:

json
"resolutions": {  "<package-name>": "<working-version-or-git-ref>"}

Then delete yarn.lock and node_modules and reinstall:

bash
rm -rf node_modules yarn.lockyarn install --ignore-engines 2>&1 | tail -10

Step 7: Fix unmet @openfeature/web-sdk peer dependency

@grafana/runtime depends on @openfeature/react-sdk which has @openfeature/web-sdk as a peer dependency. Yarn v1 (classic) does not auto-install peer deps.

Check if the plugin uses yarn classic:

bash
yarn --version 2>&1 | head -1

If version starts with 1., check for warnings:

bash
yarn install --ignore-engines 2>&1 | grep "unmet peer dependency.*openfeature/web-sdk"

If warnings are found:

bash
yarn add -D @openfeature/web-sdk @openfeature/core --ignore-engines

Skip condition: Yarn v2+ or npm v7+ (peer deps are auto-installed).


Step 8: Fix source code issues

bash
grep -rn "ReactDOM\.render\|ReactDOM\.unmountComponentAtNode\|ReactDOM\.findDOMNode" src/ --include="*.tsx" --include="*.ts"grep -rn "\.defaultProps\s*=" src/ --include="*.tsx" --include="*.ts"grep -rn "\.propTypes\s*=" src/ --include="*.tsx" --include="*.ts"grep -rn "contextTypes\|getChildContext" src/ --include="*.tsx" --include="*.ts"grep -rn "createFactory" src/ --include="*.tsx" --include="*.ts"grep -rn "ChangeEvent<HTMLInputElement>" src/ --include="*.tsx" --include="*.ts"
PatternFix
ReactDOM.render()createRoot(container).render(element)
defaultProps on function componentsMove to destructured parameter defaults
defaultProps on class componentsLeave — still works
propTypesRemove
contextTypes / getChildContextUse React.createContext() + useContext()
createFactoryUse JSX or createElement()
ChangeEvent<HTMLInputElement> on checkboxChange to FormEvent<HTMLInputElement>

Step 9: Build, typecheck, test

bash
rm -rf node_modules distyarn install --ignore-engines 2>&1 | tail -10yarn build 2>&1 | tail -10yarn typecheck 2>&1 | tail -10yarn test --watchAll=false 2>&1 | tail -10
ErrorFix
Cannot find module 'react/jsx-runtime'Step 4 not applied — re-run create-plugin add
Cannot find module '@openfeature/web-sdk'Step 7 — yarn add -D @openfeature/web-sdk @openfeature/core
Can't resolve '@grafana/i18n'yarn add @grafana/i18n@^12.2.0
Cannot read properties of undefined (reading 'ReactCurrentOwner')Bump @grafana-cloud/* packages — see Step 6
aria-label is missing on icon-only ButtonAdd aria-label prop (newer @grafana/ui requires it)
Stale git hash in yarn.lockAdd resolutions in package.json, delete lockfile, reinstall

For detailed known issues (i18n crash, @grafana/schema type breaks, publicPath mismatch), see references/known-issues.md [blocked].


Step 10: Update CI (if applicable)

bash
grep -rn "plugin-ci-workflows\|e2e-version" .github/workflows/ 2>/dev/null
  • plugin-ci-workflows@main or >= 6.0.0 → already tests React 19. No changes needed.
  • plugin-actions/e2e-version → add skip-grafana-react-19-preview-image: false.
  • Neither found → test manually with GRAFANA_VERSION=dev-preview-react19 docker compose up --build.

Step 11: Squash and push

bash
git reset --soft origin/maingit add -Agit commit -m "fix: Prepare plugin for React 19 compatibility"

Commit message body should list: create-plugin version change, ESLint 9 migration, key dependency bumps, and any source code fixes.


References

來源與署名

來源:grafana/skills位於skills/grafana-plugins/react-19-plugin-migration提交1ccacf2

授權條款: Apache-2.0

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架

更多來自 grafana/skills 的技能

Plugin Bundle Size

grafana

指導使用 React.lazy、Suspense 與 webpack 程式碼分割來最佳化 Grafana 應用程式外掛的打包體積。

Software Development279今天更新

Grafana Scenes

grafana

使用 @grafana/scenes 框架建置 Grafana 外掛頁面,涵蓋場景、面板、變數與下鑽導覽。

Software Development279今天更新

Check Npm

grafana

對 JS/TS 儲存庫的 npm、yarn 或 pnpm 設定進行唯讀供應鏈強化稽核。

Security279今天更新

Mimir

grafana

指導架設與維運 Grafana Mimir,用於可擴充、多租戶、長期的 Prometheus 與 OTLP 指標儲存。

DevOps & Cloud279今天更新

K6 Trend Analysis

grafana

Analyze Grafana Cloud k6 test run trends over time. Detects slow metric drift (e.g., P95 latency creeping up while still passing thresholds), computes headroom to thresholds, flags anomalies, and recommends threshold tightening. Use when the user asks about test performance trends, wants to know if metrics are degrading, asks whether thresholds should be tightened, or wants a health check across recent runs for a specific test. Trigger on phrases like "how is my test trending", "is P95 getting worse", "check for performance regression", "should I tighten thresholds", "are my tests degrading", "show me trends for test X", "analyze my k6 test runs", or "is my test getting slower". Also trigger when a user asks to check all tests in a project -- run this skill once per test and synthesize.

待分類279今天更新

K6 Test Maintenance

grafana

維護與改善現有 k6 負載測試指令碼:收緊閾值、版本移轉、重構以及最佳實務稽核。

Software Development279今天更新