Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize transform to fix long standing useForm bug #1718

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

aviemet
Copy link

@aviemet aviemet commented Nov 6, 2023

I'm opening another PR to fix this bug (#1171, #1131, #1491, #1631)

In the React useForm package, the transform function is set as a local variable in the component. This means that if the page triggers any re-render, the transform variable is re-initialized to the placeholder function ((data) => data). For this reason, it's more likely than not that the transform method does nothing, rendering the docs inaccurate.

The previous PRs were closed without being read. I think the whole React community here would really appreciate this bug finally being fixed.

@mattsims
Copy link

@reinink Any idea when this might be merged? 🙏

@mochetts
Copy link

mochetts commented Dec 19, 2023

I need this fix as well! The transform callback is being overridden by the default (data) => data after doing something basic like form.setData.

Repro steps:

const myCallback = (data) => { 
 console.log("myCallback")
 return data
}
form.transform(myCallback)
form.post('some/url', { onSuccess: ({ props }) => {
  form.setData(props.formData)
  form.post('some/url') // "myCallback" is not printed out
})

@mochetts
Copy link

mochetts commented Dec 19, 2023

I added a package containing this fix in the npm registry if anyone is interested:
https://www.npmjs.com/package/@moraki/inertia-react

@dac514
Copy link

dac514 commented Dec 28, 2023

Yay, thanks! Now what?

@dac-humi
Copy link

Please forgive me for tagging... @claudiodekker @jessarcher @thecrypticace
Can this PR get some feedback? Thanks for your time and hard work.

@aviemet
Copy link
Author

aviemet commented Mar 12, 2024

It would sure be great to get this long standing bug fixed. Hoping this is the bump that gets attention.
@reinink

jrson83 added a commit to inertiajs-revamped/inertia that referenced this pull request Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants