Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions FORK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Why this fork exists

Upstream is [`Piktos-Media/react-formgen`](https://github.com/Piktos-Media/react-formgen). This fork
carries one change: dependency build scripts are allowed so that installing the repo as a git
dependency can finish.

The repo is consumed by subdirectory (`packages/zod`), and installing a git dependency runs its
`prepare` script, which runs a nested workspace install here. pnpm >= 10 blocks dependency build
scripts by default and a nested install cannot be approved interactively, so it fails with
`ERR_PNPM_IGNORED_BUILDS`. That only shows up on a cold pnpm store — an existing store already has
the package prepared, which is why it looked fine for a long time.

## Consumers

`horang-corp/service-frontend` pins this fork through `pnpm-workspace.yaml`:

```yaml
overrides:
'@react-formgen/zod': github:rycont/react-formgen#<sha>&path:packages/zod
```

Two notes for whoever touches that pin.

Use the `github:` form with `&path:`, not a `codeload` tarball URL with `#path:`. pnpm does not read
`#path:` on a plain tarball URL — it installs the repository root (`@react-formgen/monorepo`)
instead, with an empty dependency set.

Bump to a new commit rather than reusing one that a store has already seen as the repository root.
pnpm keys its store by tarball integrity and ignores the subdirectory, so the same commit cannot be
stored both ways; the second one fails with `ERR_PNPM_UNEXPECTED_PKG_CONTENT_IN_STORE`.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@react-formgen/monorepo",
"version": "0.0.0",
"packageManager": "pnpm@10.9.0",
"scripts": {
"dev": "pnpm run --filter website dev",
"build": "pnpm run build:core && pnpm run build:js && pnpm run build:yup && pnpm run build:zod",
Expand Down
5 changes: 4 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@
],
"scripts": {
"build": "vite build && tsc",
"prepare": "npm run build",
"prepublishOnly": "npm run build",
"analyze": "vite build --mode analyze",
"test": "vitest",
"coverage": "vitest --coverage"
},
"dependencies": {
"@types/react": "^18.0.0 || ^19.0.0",
"nanoid": "^5.0.7",
"zustand": "^4.5.2"
},
"peerDependencies": {
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0"
"react-dom": "^18.0.0 || ^19.0.0",
"@types/react": "^18.0.0 || ^19.0.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.4.8",
Expand Down
5 changes: 4 additions & 1 deletion packages/zod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@
],
"scripts": {
"build": "vite build && tsc",
"prepare": "pnpm -C ../.. build:core && pnpm run build",
"prepublishOnly": "npm run build",
"analyze": "vite build --mode analyze"
},
"dependencies": {
"@react-formgen/core": "0.0.0-alpha.27"
"@react-formgen/core": "0.0.0-alpha.27",
"@types/react": "^18.0.0 || ^19.0.0"
},
"peerDependencies": {
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0",
"@types/react": "^18.0.0 || ^19.0.0",
"zod": "^3.25.61"
},
"devDependencies": {
Expand Down
13 changes: 13 additions & 0 deletions packages/zod/src/components/RenderTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import type * as z from "zod/v4/core";
import { RenderTemplateProps } from "./types";
import { useTemplates } from "..";
import { unwrapSchema } from "../utils";
Expand All @@ -24,6 +25,7 @@ export const RenderTemplate: React.FC<RenderTemplateProps> = ({
UnionTemplate,
TupleTemplate,
EnumTemplate,
LiteralTemplate,
} = useTemplates();

// Let's first unwrap the schema to get to the core type
Expand Down Expand Up @@ -62,6 +64,17 @@ export const RenderTemplate: React.FC<RenderTemplateProps> = ({
case "tuple":
return <TupleTemplate schema={schema} path={path} />;

case "literal":
return <LiteralTemplate schema={schema} path={path} />;

case "lazy": {
// Lazy schemas contain a getter function that returns the actual schema
const lazySchema = coreSchema as z.$ZodLazy;
const actualSchema = lazySchema._zod.def.getter();
// Recursively render the actual schema
return <RenderTemplate schema={actualSchema} path={path} />;
}

default:
// Unknown or unsupported schema type
console.error(
Expand Down
1 change: 1 addition & 0 deletions packages/zod/src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export type Templates = {
UnionTemplate: React.FC<{ schema: z.$ZodType; path: string[] }>;
TupleTemplate: React.FC<{ schema: z.$ZodType; path: string[] }>;
EnumTemplate: React.FC<{ schema: z.$ZodType; path: string[] }>;
LiteralTemplate: React.FC<{ schema: z.$ZodType; path: string[] }>;
};

/**
Expand Down
26 changes: 16 additions & 10 deletions packages/zod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import {
createFormProviderAndHooks,
FormState as CoreFormState,
} from "@react-formgen/core";
import type {
FormProviderProps as CoreFormProviderProps,
FormProps as CoreFormProps,
RenderTemplateProps,
} from "@react-formgen/core";
import type { FC, ComponentType } from "react";

import type * as z from "zod/v4/core";
import { generateInitialData } from "./utils";
Expand Down Expand Up @@ -37,21 +43,21 @@ const getIssuesAtPath = (
/**
* Create the form provider and hooks using the core factory
*/
const {
FormProvider: CoreFormProvider,
useFormContext,
useFormDataAtPath,
useErrorsAtPath,
useArrayTemplate,
useTemplates,
useRenderTemplate,
Form: CoreForm,
} = createFormProviderAndHooks<z.$ZodType, z.$ZodIssue>(
const _tools = createFormProviderAndHooks<z.$ZodType, z.$ZodIssue>(
createInitialData,
getIssuesAtPath,
DefaultRenderTemplate
);

const CoreFormProvider: FC<Omit<CoreFormProviderProps<z.$ZodType>, "createInitialData">> = _tools.FormProvider;
const useFormContext = _tools.useFormContext;
const useFormDataAtPath = _tools.useFormDataAtPath;
const useErrorsAtPath = _tools.useErrorsAtPath;
const useArrayTemplate = _tools.useArrayTemplate;
const useTemplates: () => { [key: string]: ComponentType<any> } = _tools.useTemplates;
const useRenderTemplate: () => ComponentType<RenderTemplateProps<z.$ZodType>> = _tools.useRenderTemplate;
const CoreForm: FC<CoreFormProps<z.$ZodType, z.$ZodIssue>> = _tools.Form;

export type FormState = CoreFormState<z.$ZodType, z.$ZodIssue>;

const FormProvider = CoreFormProvider as React.FC<FormProviderProps>;
Expand Down
13 changes: 13 additions & 0 deletions packages/zod/src/utils/generateInitialData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ export function generateInitialData(schema: z.$ZodType): ZeroState {
return enumDef.entries[firstKey];
}

case "literal": {
const literalSchema = coreSchema as z.$ZodLiteral;
return Array.from(literalSchema._zod.def.values)[0];
}

case "lazy": {
// Lazy schemas contain a getter function that returns the actual schema
const lazySchema = coreSchema as z.$ZodLazy;
const actualSchema = lazySchema._zod.def.getter();
// Recursively generate initial data for the actual schema
return generateInitialData(actualSchema);
}

default:
console.error(`Unsupported schema type: ${def.type}`);
return undefined;
Expand Down
6 changes: 6 additions & 0 deletions packages/zod/src/utils/unwrapSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export function unwrapSchema(schema: z.$ZodType): z.$ZodTypes {
return unwrapSchema(nonOptionalSchema._zod.def.innerType);
}

case "lazy": {
const lazySchema = typedSchema as z.$ZodLazy;
const actualSchema = lazySchema._zod.def.getter();
return unwrapSchema(actualSchema);
}

default:
return typedSchema;
}
Expand Down
Loading