TanStackT
TanStack2w ago
4 replies
military-pink

Leaking imports?

I was looking into my client buble and I saw some server related stuff. Ai told me the following:

Before (leaks to client):
import { drizzle } from 'drizzle-orm/d1';  // Top-level = bundled
import * as schema from '@server/db/schema';
export const getChildren = createServerFn()
  .handler(async () => {
    const db = drizzle(env.DB);
    return db.select().from(schema.children);
  });

After (server-only):
export const getChildren = createServerFn()
  .handler(async () => {
    const { drizzle } = await import('drizzle-orm/d1');
    const schema = await import('@server/db/schema');
    const db = drizzle(env.DB);
    return db.select().from(schema.children);
  });


Is this true?

Do I need to do all imports inside the server functions? Also same for server.handlers? do I need to use dynamic imports inside server function / handlers?
Was this page helpful?