diff --git a/packages/react/src/__tests__/schema.markup.spec.tsx b/packages/react/src/__tests__/schema.markup.spec.tsx index d78e39c79f9..f19404aa9f7 100644 --- a/packages/react/src/__tests__/schema.markup.spec.tsx +++ b/packages/react/src/__tests__/schema.markup.spec.tsx @@ -486,3 +486,70 @@ test('schema reactions', async () => { expect(queryByTestId('ccc')).toBeVisible() }) }) + +test('expression scope', async () => { + let aa = false + let bb = false + let cc = false + const form = createForm() + const SchemaField = createSchemaField({ + components: { + Input, + }, + scope: { + aa() { + aa = true + }, + }, + }) + + const scope = { + bb() { + bb = true + }, + cc() { + cc = true + }, + } + + const schema = { + type: 'object', + properties: { + aa: { + type: 'string', + 'x-component': 'Input', + 'x-reactions': '{{ aa }}', + }, + bb: { + type: 'string', + 'x-component': 'Input', + 'x-reactions': '{{ bb }}', + }, + cc: { + type: 'string', + 'x-component': 'Input', + 'x-reactions': { + dependencies: ['aa'], + fulfill: { + run: '{{ cc() }}', + }, + }, + }, + }, + } + + const { queryByTestId } = render( + + + + ) + + await waitFor(() => queryByTestId('aa')) + expect(aa).toBeTruthy() + + await waitFor(() => queryByTestId('bb')) + expect(bb).toBeTruthy() + + await waitFor(() => queryByTestId('cc')) + expect(cc).toBeTruthy() +}) diff --git a/packages/react/src/components/RecursionField.tsx b/packages/react/src/components/RecursionField.tsx index e9ccf548f0f..7631f411a70 100644 --- a/packages/react/src/components/RecursionField.tsx +++ b/packages/react/src/components/RecursionField.tsx @@ -19,13 +19,10 @@ export const RecursionField: React.FC = (props) => { const options = useContext(SchemaOptionsContext) const scope = useContext(SchemaExpressionScopeContext) const fieldSchema = useMemo(() => { - return schema?.compile({ - ...options.scope, - ...scope, - }) + return schema?.compile(scope) }, [schema]) const fieldProps = useMemo( - () => fieldSchema?.toFieldProps(options) as any, + () => fieldSchema?.toFieldProps({ ...options, scope }) as any, [fieldSchema] ) const getBasePath = () => {