Next.js, needing Tina in production

originally posted by saimeunt in the Tina Slack

Hi there,

Following up on the discussions about getting rid of Tina in production earlier this monday.

I have the opposite use case, I’d like to register Tina forms in prod to edit the content and save it through a GraphQL mutation hooking on the onSubmit callback, bypassing the standard git backend process.

I’ve seen on GH that it’s been discussed:

However the idea of running forms in production seems to have been dismissed for now by this PR:

Question: is it on the roadmap to reintroduce form registration in production at some point through a config option?

I think you’re exactly right. The early returns make sense in useRemarkForm and useJsonForm –since there’s no way they could work in a production Gatsby site–but it’s far too presumptuous to make that assumption in useForm .

Follow-up — tor people needing Tina in production you can use this:

import { useForm, usePlugins } from 'react-tinacms';

// eslint-disable-next-line import/prefer-default-export
export function useLocalForm(options, watch = {}) {
   * We're returning early here which means all the hooks called by this hook
   * violate the rules of hooks. In the case of the check for
   * `NODE_ENV === 'production'` this should be a non-issue because NODE_ENV
   * will never change at runtime.
  /* if (process.env.NODE_ENV === 'production') {
    return [options.initialValues, undefined];
  } */
  /* eslint-disable-next-line react-hooks/rules-of-hooks */
  const [values, form] = useForm(options, watch);
  /* eslint-disable-next-line react-hooks/rules-of-hooks */
  return [values, form];

I’m just commenting out the early return from

Then import this function instead of import { useLocalForm } from ‘react-tinacms’;

1 Like

We’ve recently changed this behaviouor. useForm no longer exits early in production: