form icon indicating copy to clipboard operation
form copied to clipboard

feat(react-form): add display name to components

Open kidonng opened this issue 7 months ago • 5 comments

Currently, with the following code:

<AppForm>
  <ContainerForm>
    <AppField name="animal">
      {() => <RadioGroupField {...props} />}
    </AppField>
  </ContainerForm>
</AppForm>

Storybook's "Show code" function displays "No Display Name" for <AppForm> and <AppField>:

Screenshot 2025-05-08 at 1 17 07 PM

By assigning a displayName, they are displayed with correct names:

Screenshot 2025-05-08 at 1 16 20 PM

Assigning displayName is necessary since merely this...

    const AppForm = useMemo(() => {
-      return (({ children }) => {
+      const AppForm = (({ children }) => {

...would display as <AppForm2> instead since it is renamed when compiled:

const AppForm = useMemo(() => {
  const AppForm2 = ({ children }) => {
    return /* @__PURE__ */ jsx(formContext.Provider, { value: form, children });
  };
  AppForm2.displayName = "AppForm";
  return AppForm2;
}, [form]);

EDIT: since assigning displayName triggers a lint error, I'm resorting to simple named functions.

kidonng avatar May 08 '25 05:05 kidonng

View your CI Pipeline Execution ↗ for commit 714de5934b27a4b94109197197c24bf967ba563a.

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 5s View ↗

☁️ Nx Cloud last updated this comment at 2025-05-08 05:40:07 UTC

nx-cloud[bot] avatar May 08 '25 05:05 nx-cloud[bot]

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@1491
@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@1491
@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@1491
@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@1491
@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@1491
@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@1491
@tanstack/svelte-form

npm i https://pkg.pr.new/@tanstack/svelte-form@1491

commit: 714de59

pkg-pr-new[bot] avatar May 08 '25 05:05 pkg-pr-new[bot]

Well... https://github.com/TanStack/form/actions/runs/14899285839/job/41847764667?pr=1491#step:6:185

/home/workflows/workspace/packages/react-form/src/createFormHook.tsx
  278:7   error    This mutates a variable that React considers immutable                                 react-compiler/react-compiler

I am fine without the better displayName.

I also just notice more components like <Subscribe> needs this.

kidonng avatar May 08 '25 05:05 kidonng

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 43.94%. Comparing base (3fe66dd) to head (714de59). Report is 53 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1491       +/-   ##
===========================================
- Coverage   88.96%   43.94%   -45.02%     
===========================================
  Files          31       13       -18     
  Lines        1396      157     -1239     
  Branches      353       26      -327     
===========================================
- Hits         1242       69     -1173     
+ Misses        137       77       -60     
+ Partials       17       11        -6     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar May 08 '25 05:05 codecov[bot]

Thank you @kidonng just ran into this in Storybook docs.

cgatian avatar May 27 '25 21:05 cgatian