React Quick Start examples fail at runtime: Renderer must be wrapped in JSONUIProvider

Aperta Adatta ai principianti
#443 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@jitui-123 ci sta già lavorando.

Dal 29/10/2026.

  • #445 di @jitui-123 — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
1-3 ore
Idoneità per principianti
86/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript

Direzione di ricerca

Leggi gli esempi React alle righe 119, 188 e 280 del README.md nella directory principale, poi controlla l’esempio Solid alle righe 231–247 per il modello del provider. Aggiorna i tre esempi React in modo da racchiudere Renderer in JSONUIProvider, usando come riferimento la versione funzionante nell’issue. Il lavoro è completato quando ogni snippet React documentato include il provider richiesto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

The React Quick Start in the root README.md and the @json-render/react usage examples render <Renderer> without any provider. Copying these snippets verbatim crashes at runtime:

Error: useVisibility must be used within a VisibilityProvider
    at useVisibility (...)
    at ReactiveElementRenderer (...)

Where

Root README.md:

  • Line 119 — React Quick Start (Renderer in a Dashboard component, no provider)
  • Line 188 — React renderer section, "That's it" example
  • Line 280 — shadcn/ui section

The Solid section (line 231–247) is the only renderer example that wraps <JSONUIProvider> correctly, which suggests this was known but never backported to the React examples.

Why it fails

Renderer calls useVisibility(), which throws unless a VisibilityProvider is above it:

throw new Error("useVisibility must be used within a VisibilityProvider");

JSONUIProvider is what supplies it. Its implementation nests the required providers:

<StateProvider>
  <VisibilityProvider>
    <ValidationProvider>
      <ActionProvider>
        <FunctionsContext.Provider>
          <DirectivesContext.Provider>
            {children}
            <ConfirmationDialogManager />

So the provider is not optional for React — only for renderers whose README already shows it.

Reproduction

import { defineCatalog } from "@json-render/core";
import { schema } from "@json-render/react/schema";
import { defineRegistry, Renderer } from "@json-render/react";

const catalog = defineCatalog(schema, { components: { /* ... */ }, actions: {} });
const { registry } = defineRegistry(catalog, { components: { /* ... */ } });

const spec = { root: "a", elements: { a: { type: "Card", props: {}, children: [] } } };

// Exactly as documented
<Renderer spec={spec} registry={registry} />;
// -> Error: useVisibility must be used within a VisibilityProvider

Working version

import { defineRegistry, Renderer, JSONUIProvider } from "@json-render/react";

<JSONUIProvider registry={registry} initialState={spec.state ?? {}}>
  <Renderer spec={spec} registry={registry} />
</JSONUIProvider>

Environment

  • @json-render/core 0.21.3
  • @json-render/react 0.21.3
  • @json-render/shadcn 0.21.3
  • react / react-dom 19
  • zod 4
  • Vite 8, Node 26

Suggested fix

Update the three README snippets to include <JSONUIProvider>, or add a one-line note in the Quick Start that Renderer must be wrapped in a provider. A provider-missing error that names the required component (e.g. "wrap <Renderer> in <JSONUIProvider>") would also save a lot of time for newcomers.


This is not a bug report — the provider design is reasonable. The issue is that the primary React examples in the README don't work as written.

Lingua principale
TypeScript
Stelle
20k
Fork
1.1k
Merge medio
1g 18h
PR unite (30g)
25

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel-labs/json-render

Tutte le issue di vercel-labs/json-render

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.