|
| 1 | +// Test React 19 error callbacks by updating DOM elements |
| 2 | +export const onCaughtError = ({ error, errorInfo }) => { |
| 3 | + console.log("[Test] onCaughtError callback called!", error?.message || error) |
| 4 | + |
| 5 | + // Update DOM to show caught error |
| 6 | + if (typeof document !== "undefined") { |
| 7 | + console.log("[Test] Updating DOM for caught error") |
| 8 | + const errorDisplay = document.getElementById("caught-error-display") |
| 9 | + if (errorDisplay) { |
| 10 | + errorDisplay.textContent = `Caught Error: ${error?.message || error}` |
| 11 | + errorDisplay.style.display = "block" |
| 12 | + console.log("[Test] Updated caught error display") |
| 13 | + } else { |
| 14 | + console.log("[Test] Could not find caught-error-display element") |
| 15 | + } |
| 16 | + |
| 17 | + // Increment counter |
| 18 | + const counter = document.getElementById("caught-error-count") |
| 19 | + if (counter) { |
| 20 | + const currentCount = parseInt(counter.textContent) || 0 |
| 21 | + counter.textContent = (currentCount + 1).toString() |
| 22 | + console.log("[Test] Updated caught error counter to:", currentCount + 1) |
| 23 | + } else { |
| 24 | + console.log("[Test] Could not find caught-error-count element") |
| 25 | + } |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +export const onUncaughtError = ({ error, errorInfo }) => { |
| 30 | + console.log( |
| 31 | + "[Test] onUncaughtError callback called!", |
| 32 | + error?.message || error |
| 33 | + ) |
| 34 | + |
| 35 | + // Update DOM to show uncaught error |
| 36 | + if (typeof document !== "undefined") { |
| 37 | + console.log("[Test] Updating DOM for uncaught error") |
| 38 | + const errorDisplay = document.getElementById("uncaught-error-display") |
| 39 | + if (errorDisplay) { |
| 40 | + errorDisplay.textContent = `Uncaught Error: ${error?.message || error}` |
| 41 | + errorDisplay.style.display = "block" |
| 42 | + console.log("[Test] Updated uncaught error display") |
| 43 | + } else { |
| 44 | + console.log("[Test] Could not find uncaught-error-display element") |
| 45 | + } |
| 46 | + |
| 47 | + // Increment counter |
| 48 | + const counter = document.getElementById("uncaught-error-count") |
| 49 | + if (counter) { |
| 50 | + const currentCount = parseInt(counter.textContent) || 0 |
| 51 | + counter.textContent = (currentCount + 1).toString() |
| 52 | + console.log("[Test] Updated uncaught error counter to:", currentCount + 1) |
| 53 | + } else { |
| 54 | + console.log("[Test] Could not find uncaught-error-count element") |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +export const onClientEntry = () => { |
| 60 | + console.log("[Test] onClientEntry called") |
| 61 | + // Try to access React to check version |
| 62 | + try { |
| 63 | + const React = require("react") |
| 64 | + console.log("[Test] React version from require:", React.version) |
| 65 | + } catch (e) { |
| 66 | + console.log("[Test] Could not require React:", e) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +// Debug: Log when this file is loaded |
| 71 | +console.log("[Test] gatsby-browser.js loaded, React version check...") |
| 72 | +if (typeof window !== "undefined" && window.React) { |
| 73 | + console.log("[Test] React version:", window.React.version) |
| 74 | +} else { |
| 75 | + console.log("[Test] React not available on window") |
| 76 | +} |
0 commit comments