Repository navigation
Commit 55020c3
fix(form): recompute formula fields from the live inputs before judging field rules (#35116)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8VjQGdf4i6Ff5bzwJcTFarg)_
Fixes #35033
Clause-②: yes (widening) — one new member on the `@object-ui/core`
package entry (the client formula pass,
`ui/packages/core/src/evaluator/formulaRecord.ts`), nothing removed or
renamed
Metadata-protocol: none
## 维护者速读
- 改了什么:表单在判 `visibleWhen` / `requiredWhen` / `readonlyWhen`
之前,先用页面上正在输入的值把对象的公式字段算一遍(对象表单渲染器 + 控制台表单视图页 FormPage
两处),`@object-ui/core` 多导出一个 `planObjectFormulas`。
- 为什么改:必填字段的 `visibleWhen`
读公式时,新建表单怎么填都不显示(公式没画在表单上时还会整单拒绝提交),编辑跨过条件也不显示,而服务端按算出来的值要求必填——用户无法保存。
- 风险与回滚:只影响声明了字段规则、且对象有公式字段的表单;算不出的公式(跨引用、`label()`、`current_user`
等)一律按"显示且必填、不拒绝提交"处理,与服务端一致。回滚即 revert 本 PR。
-
先看:`ui/packages/core/src/evaluator/formulaRecord.ts`(`planObjectFormulas`
的可算/不可算分类与读序)、`ui/packages/components/src/renderers/form/form.tsx`(`ruleRecord`
末行与 `fields`
memo)、`ui/apps/console/src/components/FormPage.tsx`(`ruleValues`
只进规则判定,提交载荷仍是 `values`)。
- 两分钟验证:`pnpm --dir ui exec vitest run
packages/components/src/renderers/form/__tests__/form-formula-recompute-35033.test.tsx`,预期
5 passed。
- 需要你做的:无,席位落地(发版冻结期间保持 draft)。
## What changes
- `@object-ui/core`: new `planObjectFormulas(fields)` (exported from the
package entry, with its `ObjectFormulaPlan` type). It plans the served
object's `formula` fields once and computes them over a record in the
platform's read order (`formulaReadOrder`), with the canonical
`ExpressionEngine`, as objectql's `formulaValuesFor` does on the server:
- **A fault a read shares** (an operator over an empty operand, an
undeclared key, a cycle, a traversal conflict): the formula reads
`null`, and the rule is judged on that `null`.
- **Unservable**: the formula reads through a reference, calls
`label()`, reads a scope root other than `record` (so
`current_user.can()` too), is served without its expression (an FLS
mask), or reads such a formula at any depth. `unservableReadsOf(pred)`
names them.
- Object form renderer (`form.tsx`): reads the object's formulas through
`dataSource.getObjectSchema`, by the route `usePatchingUpdateActions`
already uses, and only when some field declares a rule
(`objectFormulas.ts`). `ruleRecord` = the formulas computed over (null
seed, then last-read record, then live values). A field row whose
`visibleWhen` reads an unservable formula loses that `visibleWhen`, with
one `console.warn`. The field is shown, keeps its `required`, and is no
ADR-0137 D2 submit refusal: this is the server's answer for that
predicate under ruling record 6956761249 item 3, and the client is never
stricter than the server (ADR-0124). The update-action outcome records
are recomputed after their patch too.
- Console form-view page (`FormPage.tsx`): the same pass. It was
measured as a live create/edit renderer (`/forms/:name`, `?recordId=`,
`/f/:slug`) that judges the object-level `visibleWhen` over its own
`values`, with the object's fields in hand from `/meta/object`. Only the
object-level `rules.visibleWhen` is dropped for an unservable read; the
view-level predicate is a layout gate and is left as is. The write
payload stays `values`, so a computed formula is never sent.
## Tests
-
`ui/packages/core/src/evaluator/__tests__/formulaRecord-35033.test.ts`:
10 pins on the pass (read order, no mutation, empty operand → null,
cycle → null, hop and its closure unservable, `label()` / `current_user`
/ masked expression unservable, unnameable predicate reads, and the rule
verdicts over the computed record).
-
`ui/packages/components/src/renderers/form/__tests__/form-formula-recompute-35033.test.tsx`:
5 pins on the real `form` renderer: create crossing, edit crossing,
reverse edit, hop → shown + required + submit allowed once filled, empty
operand → judged on `null` with no submit refusal.
- `ui/apps/console/src/components/FormPage.conditionalRules.test.tsx`: a
new top-level `describe` in this harness, holding the same pins for
FormPage (create, edit crossing and reverse, hop, empty operand).
- `form-required-for-action-28382.test.tsx` "does not read or note
anything on a create form": the create form now makes exactly one object
read, and it is the formula pass's, so the assertion is now
`toHaveBeenCalledTimes(1)`. The note's absence is unchanged.
### Ablation (each leg through `scripts/ablation-replace.mjs`: anchor x1
→ x0, blob changed, restored to the HEAD blob; `git diff HEAD` empty
afterwards)
| Leg | Mutation | Red | Green |
|---|---|---|---|
| form M1 | `ruleRecord`: `return formulaPlan ? formulaPlan.compute(out)
: out;` → `return out;` | create crossing, edit crossing, reverse edit,
empty operand (4/5) | hop (needs M2) |
| form M2 | `fields`: `withoutUnservableVisibleWhen(...)` →
`declaredFields` | hop (1/5) | the other 4 |
| FormPage M1 | `ruleValues`: `formulaPlan ? formulaPlan.compute(values)
: values` → `values` | create, edit crossing+reverse, empty operand
(3/4) | hop (needs M2) |
| FormPage M2 | `sections`:
`withoutUnservableRuleVisibleWhen(buildSections(...))` →
`buildSections(...)` | hop (1/4) | the other 3 |
The ablations edit sources that the tests import directly (relative
imports), so no `dist/` is involved.
## Acceptance notes
- Premise measured on `origin/main` 526282e with the real renderer
(throwaway tests, not committed): create with the formula drawn on the
form → the required field stays hidden after crossing; create with the
formula not drawn → the rule faults on the missing key, the field shows,
and every submit is refused ("Can't submit: the visibleWhen rule of
Discount note could not be evaluated."); edit crossing → stays hidden.
- The client's unservable set is the server's plus the roots the form
does not bind for a formula (`current_user`, `os`, `previous`, …). Such
a formula is shown, never hidden, so the form cannot be stricter than
the server.
- `today()` / `now()` formulas are computed with the browser clock and
no timezone; the server uses the request's execution context. Near a day
boundary the two can disagree. This is noted, not changed.
- On the server, field `requiredWhen` / `readonlyWhen` are judged over
the merged record without computing formulas (`formulaValues` feeds only
the required-when-shown `visibleWhen` on PR #34978's head). This was
read, not reproduced.
## Verification
<details><summary>Local runs on head 6334ae4</summary>
- core helper pins: Tests 10 passed (10)
- form renderer pins: Tests 5 passed (5)
- FormPage harness file: Tests 29 passed (29)
- `packages/core/src/evaluator/`,
`packages/components/src/renderers/form/`,
`apps/console/src/components/FormPage*`: 157/158 files before the 28382
pin update (the one red was that pin), and the pin file is 14/14 after
it
- every ui test that counts `getObjectSchema` reads (40 files): Test
Files 40 passed (40), Tests 486 passed (486)
- `@object-ui/core` and `@object-ui/components` type-check: exit 0. The
console type-check needs the whole console closure built, so it is
declared to CI (Type Check UI)
- eslint on the changed files: 0 errors
- overlap-check: VERDICT clean exit 0
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01JQwxbWoeMbVAavTXkbV2Cn
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 7ed18b5 commit 55020c3
10 files changed
Lines changed: 1221 additions & 17 deletions
File tree
- .changeset
- ui
- apps/console/src/components
- packages
- components/src/renderers/form
- __tests__
- core/src/evaluator
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| 128 | + | |
| 129 | + | |
127 | 130 | | |
128 | 131 | | |
129 | 132 | | |
| |||
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
139 | | - | |
| 142 | + | |
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
| |||
145 | 148 | | |
146 | 149 | | |
147 | 150 | | |
148 | | - | |
| 151 | + | |
149 | 152 | | |
| 153 | + | |
150 | 154 | | |
151 | 155 | | |
152 | 156 | | |
| |||
770 | 774 | | |
771 | 775 | | |
772 | 776 | | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| 133 | + | |
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| |||
2424 | 2426 | | |
2425 | 2427 | | |
2426 | 2428 | | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
2427 | 2473 | | |
2428 | 2474 | | |
2429 | 2475 | | |
| |||
2749 | 2795 | | |
2750 | 2796 | | |
2751 | 2797 | | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
2752 | 2816 | | |
2753 | | - | |
2754 | | - | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
2755 | 2822 | | |
2756 | 2823 | | |
2757 | 2824 | | |
| |||
2916 | 2983 | | |
2917 | 2984 | | |
2918 | 2985 | | |
2919 | | - | |
| 2986 | + | |
2920 | 2987 | | |
2921 | 2988 | | |
2922 | 2989 | | |
| |||
2947 | 3014 | | |
2948 | 3015 | | |
2949 | 3016 | | |
2950 | | - | |
| 3017 | + | |
2951 | 3018 | | |
2952 | 3019 | | |
2953 | 3020 | | |
| |||
2971 | 3038 | | |
2972 | 3039 | | |
2973 | 3040 | | |
2974 | | - | |
| 3041 | + | |
2975 | 3042 | | |
2976 | 3043 | | |
2977 | 3044 | | |
| |||
3288 | 3355 | | |
3289 | 3356 | | |
3290 | 3357 | | |
3291 | | - | |
| 3358 | + | |
3292 | 3359 | | |
3293 | 3360 | | |
3294 | 3361 | | |
| |||
3386 | 3453 | | |
3387 | 3454 | | |
3388 | 3455 | | |
3389 | | - | |
| 3456 | + | |
3390 | 3457 | | |
3391 | 3458 | | |
3392 | 3459 | | |
| |||
3577 | 3644 | | |
3578 | 3645 | | |
3579 | 3646 | | |
3580 | | - | |
| 3647 | + | |
3581 | 3648 | | |
3582 | 3649 | | |
3583 | 3650 | | |
| |||
0 commit comments