Project Overview
For this challenge, I jumped into Formbricks—the open-source, privacy-first experience management and survey platform. Setting up a heavy, production-grade Next.js stack locally always comes with its fair share of surprises, and my local environment gave me a wild ride trying to get everything to boot up cleanly.
Bug Fix or Performance Improvement
When I first spun up the project, I ran into two major roadblocks that completely halted my local dev server:
1. The Edge Runtime Crash
Next.js threw strict build errors because @formbricks/logger was executing Node.js-specific process listeners (process.on("SIGINT", ...)) inside files touched by Edge instrumentation and Sentry edge configurations. Since the Edge runtime doesn't support Node APIs, the compiler threw a fit.
2. Database & Redis Timeouts
Once the build passed, Prisma started throwing frustrating Connection terminated due to connection timeout errors when talking to the cloud-hosted Neon database pooler and Upstash Redis instance due to abrupt SSL drops and unconfigured socket limits.
Code & Fixes
Here are the exact changes I made to tame the runtime errors and database drops:
Guarding Node Process Listeners in the Logger
typescript
// Safely gate process event listeners so the Edge runtime never evaluates them
if (process.env.NEXT_RUNTIME === "nodejs") {
try {
M();
} catch (e) {
g.error(e, "Error attaching process event handlers");
}
}
Optimizing Connection Strings in .env
Code snippet
# Added explicit timeout and pool limits to stabilize remote connections
DATABASE_URL="postgresql://user:pass@host/dbname?sslmode=require&connect_timeout=30&pool_timeout=30"
REDIS_URL="rediss://...&family=4"
My Improvements
Clean Architecture Separation: Used dynamic imports and explicit environment checks against process.env.NEXT_RUNTIME === "nodejs" to cleanly isolate server-side logging and worker job scheduling from the lightweight Edge runtime.
Resilient Local Setup: Tuned connection parameters to ensure smooth, uninterrupted pooling with external cloud services, allowing local survey rendering, database migrations, and UI previews to run like a charm.
Best Use of Sentry
I configured Sentry’s error tracking boundaries (sentry.edge.config.ts and sentry.server.config.ts) using safe conditional checks. This ensures that Sentry initializes gracefully only when a DSN is provided, avoiding local noise or compilation crashes in restricted environments.
Top comments (0)