Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Trying to fix form submission to Notion and HubSpot (#46629)

Prashant Sridharan31c4205a10f5
diff --git a/packages/marketing/src/go/actions/formCrmResolver.ts b/packages/marketing/src/go/actions/formCrmResolver.ts
index 994040a2b46..a054ca750ce 100644
--- a/packages/marketing/src/go/actions/formCrmResolver.ts
+++ b/packages/marketing/src/go/actions/formCrmResolver.ts
@@ -11,7 +11,22 @@ export type FormCrmResolver = (
ref: FormRef
) => GoFormCrmConfig | undefined | Promise<GoFormCrmConfig | undefined>
-let resolver: FormCrmResolver | null = null
+/**
+ * The resolver is stored on `globalThis` rather than in a module-level variable.
+ * `instrumentation.ts` registers it via the `marketing` package barrel, while
+ * `submitFormAction` reads it via a relative import. In a bundled build those
+ * two paths can resolve to separate instances of this module, so a plain
+ * module-level singleton set on one instance is invisible to the other — the
+ * action then sees `null` and every submission fails with "Form not found".
+ * A `globalThis` slot is shared across all module instances in the process.
+ */
+const RESOLVER_KEY = Symbol.for('marketing.go.formCrmResolver')
+
+type ResolverStore = { [key: symbol]: FormCrmResolver | null | undefined }
+
+function resolverStore(): ResolverStore {
+ return globalThis as unknown as ResolverStore
+}
/**
* Register the function used by `submitFormAction` to look up the trusted CRM
@@ -23,10 +38,11 @@ let resolver: FormCrmResolver | null = null
* `submitFormAction` for the security rationale.
*/
export function setFormCrmResolver(fn: FormCrmResolver): void {
- resolver = fn
+ resolverStore()[RESOLVER_KEY] = fn
}
export async function resolveFormCrmConfig(ref: FormRef): Promise<GoFormCrmConfig | undefined> {
+ const resolver = resolverStore()[RESOLVER_KEY]
if (!resolver) return undefined
return await resolver(ref)
}