<commit_before>import React from "react"
import { ErrorBoundary } from "react-error-boundary"
import { useDebug } from "./DebugContext.js"

export const BlockErrorBoundary = ({
    children,
}: {
    children: React.ReactNode
}) => {
    const debug = useDebug()
    return debug ? (
        <ErrorBoundary FallbackComponent={BlockErrorFallback}>
            {children}
        </ErrorBoundary>
    ) : (
        <>{children}</>
    )
}

const BlockErrorFallback = ({
    error,
    resetErrorBoundary,
}: {
    error: Error
    resetErrorBoundary: VoidFunction
}): JSX.Element => {
    return (
        <div
            style={{
                textAlign: "center",
                backgroundColor: "rgba(255,0,0,0.1)",
                padding: "20px",
            }}
        >
            <h3>Error while rendering the block</h3>
            Please check the source content.
            <div>
                <button style={{ margin: "10px" }} onClick={resetErrorBoundary}>
                    Try again
                </button>
            </div>
            <div>{error.message}</div>
        </div>
    )
}<commit_msg>fix: error is undefined on firefox, guard against this<commit_after>import React from "react"
import { ErrorBoundary } from "react-error-boundary"
import { useDebug } from "./DebugContext.js"

export const BlockErrorBoundary = ({
    children,
}: {
    children: React.ReactNode
}) => {
    const debug = useDebug()
    return debug ? (
        <ErrorBoundary FallbackComponent={BlockErrorFallback}>
            {children}
        </ErrorBoundary>
    ) : (
        <>{children}</>
    )
}

const BlockErrorFallback = ({
    error,
    resetErrorBoundary,
}: {
    error?: Error
    resetErrorBoundary: VoidFunction
}): JSX.Element => {
    return (
        <div
            style={{
                textAlign: "center",
                backgroundColor: "rgba(255,0,0,0.1)",
                padding: "20px",
            }}
        >
            <h3>Error while rendering the block</h3>
            Please check the source content.
            <div>
                <button style={{ margin: "10px" }} onClick={resetErrorBoundary}>
                    Try again
                </button>
            </div>
            <div>{error?.message}</div>
        </div>
    )
}
{'fraction_non_alphanumeric': 0.12570929725010913, 'fraction_numerical': 0.011348756001745963, 'mean_word_length': 1.764776839565742, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4207916', 'n_tokens_mistral': 658, 'n_tokens_neox': 637, 'n_words': 144}