vercel-labs / vercel-labs/json-render

Will result in multiple renderings

Open
#54 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
16.8k
Forks
901
Avg merge
3h 14m
Merged PRs (30d)
4

Description

import {
  JSONUIProvider,
  Renderer,
} from "@json-render/react";
import { registry } from "./components/config";

export default function App() {
  const uiTree = {
    root: "chart",
    elements: {
      chart:{
        key:'chart',
        type:'Stack',
        props:{
          direction:'vertical',
          gap:'lg',
          className:'w-full'
        },
        children:['grid','label']
      },

      grid: {
        key: "grid",
        type: "CollapsibleItem",
        props: {
          title: "颜色",
          header: true,
          path: "/grid/enabled",
        },
        children: ["gridColor", "gridBgColor"],
      },
      gridColor: {
        key: "gridColor",
        type: "Input",
        props: {
          path: "/grid/color",
          type: "text",
          placeholder: "请输入颜色",
        },
      },
      gridBgColor: {
        key: "gridBgColor",
        type: "Input",
        props: {
          path: "/grid/bgColor",
          type: "text",
          placeholder: "请输入背景颜色",
        },
      },
      label: {
        key: "label",
        type: "CollapsibleItem",
        props: {
          title: "标题",
          header: true,
          path: "/label/enabled",
        },
        children: ["labelName", "labelSize"],
      },
      labelName:{
        key:'labelName',
        type:'Input',
        props:{
          path:'/label/name',
          type:'text',
          placeholder:'请输入标签名称'
        }
      },
      labelSize:{
        key:"labelsize",
        type:'Input',
        props:{
          path:'/label/size',
          type:'text',
          placeholder:'请输入标签大小'
        }
      }
    },
  };

  const handleChange = (path, value) => {
    console.log("handleChange", path, value);
  };

  return (
    <div className="p-8 min-h-screen bg-background">
      <h1 className="text-2xl font-bold mb-4">Config2 UI</h1>
      <div className="max-w-2xl">
        <JSONUIProvider
          onDataChange={handleChange}
          registry={registry}
          initialData={{
            grid: {
              enabled: true,
              color: "黑色",
              bgColor: "",
            },
            label:{
              enabled:true,
              name:'标签',
              size:'12px'
            }
          }}
        >
          <Renderer tree={uiTree} registry={registry} />
        </JSONUIProvider>
      </div>
    </div>
  );
}

Image Image When I update one of the inputs, it causes all the components to be re-rendered.

how to resolve ?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the supplied App reproduction with JSONUIProvider, Renderer, and the registry from ./components/config. Start by tracing updates through JSONUIProvider and Renderer while changing one Input, then identify which components rerender. Done means the reported behavior is explained and the reproduction no longer rerenders unaffected components, with coverage added if the project has a relevant test location.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.