Skip to content

Commit

Permalink
fix(react): fix markup field is not work with strict-mode (#3088)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed May 3, 2022
1 parent fcb4e4c commit 431c3db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/guide/issue-helper.md
Expand Up @@ -100,7 +100,7 @@ const createIssueURL = ({
type,
title,
version,
package,
package: pkg,
reproduceLink,
reproduceStep,
expected,
Expand Down Expand Up @@ -129,7 +129,7 @@ ${expected || ''}
${actually || ''}
### Package
${package}@${version}
${pkg}@${version}
---
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/issue-helper.zh-CN.md
Expand Up @@ -100,7 +100,7 @@ const createIssueURL = ({
type,
title,
version,
package,
package: pkg,
reproduceLink,
reproduceStep,
expected,
Expand Down Expand Up @@ -129,7 +129,7 @@ ${expected || ''}
${actually || ''}
### Package
${package}@${version}
${pkg}@${version}
---
Expand Down Expand Up @@ -351,7 +351,7 @@ export default () => {
请尽可能详尽地说明这个需求的用例和场景。最重要的是:解释清楚是怎样的用户体验需求催生了这个功能上的需求。
</p>
<p>
Fomrily 的一个重要设计原则是保持 API
Formily 的一个重要设计原则是保持 API
的简洁和直接。通常来说,我们只考虑添加在现有的 API
下无法轻松实现的功能。新功能的用例也应当足够常见。
</p>
Expand Down
24 changes: 14 additions & 10 deletions packages/react/src/components/SchemaField.tsx
@@ -1,6 +1,6 @@
import React, { useContext, Fragment } from 'react'
import { ISchema, Schema } from '@formily/json-schema'
import { RecursionField } from '.'
import { RecursionField } from './RecursionField'
import { render } from '../shared/render'
import {
SchemaMarkupContext,
Expand Down Expand Up @@ -78,25 +78,22 @@ export function createSchemaField<Components extends SchemaReactComponents>(

SchemaField.displayName = 'SchemaField'

function MarkupField<
Decorator extends ReactComponentPath<Components>,
Component extends ReactComponentPath<Components>
>(props: ISchemaMarkupFieldProps<Components, Component, Decorator>) {
function MarkupRender(props: any) {
const parent = useContext(SchemaMarkupContext)
if (!parent) return <Fragment />
const renderChildren = () => {
return <React.Fragment>{props.children}</React.Fragment>
}
const appendArraySchema = (schema: ISchema) => {
if (parent.items) {
return parent.addProperty(name, schema)
const items = parent.items as Schema
if (items && items.name !== props.name) {
return parent.addProperty(props.name, schema)
} else {
return parent.setItems(props)
return parent.setItems(schema)
}
}
const name = props.name || getRandomName()
if (parent.type === 'object' || parent.type === 'void') {
const schema = parent.addProperty(name, props)
const schema = parent.addProperty(props.name, props)
return (
<SchemaMarkupContext.Provider value={schema}>
{renderChildren()}
Expand All @@ -116,6 +113,13 @@ export function createSchemaField<Components extends SchemaReactComponents>(
}
}

function MarkupField<
Decorator extends ReactComponentPath<Components>,
Component extends ReactComponentPath<Components>
>(props: ISchemaMarkupFieldProps<Components, Component, Decorator>) {
return <MarkupRender {...props} name={props.name || getRandomName()} />
}

MarkupField.displayName = 'MarkupField'

function StringField<
Expand Down

0 comments on commit 431c3db

Please sign in to comment.