Skip to content

feat(static): add clientInit option for pre-hydration initialization#43

Merged
uhyo merged 2 commits intomasterfrom
feat/client-init
Feb 1, 2026
Merged

feat(static): add clientInit option for pre-hydration initialization#43
uhyo merged 2 commits intomasterfrom
feat/client-init

Conversation

@uhyo
Copy link
Owner

@uhyo uhyo commented Feb 1, 2026

Summary

  • Add a new optional clientInit configuration option that allows users to specify a module that runs on the client side before React hydration
  • This enables client-side instrumentation like Sentry, analytics, or feature flags
  • When not configured, the virtual module returns an empty string (no-op, zero bundle overhead)

Changes

  • Add clientInit?: string to FunstackStaticOptions interface
  • Add virtual:funstack/client-init virtual module handling in plugin
  • Import client-init at top of client entry before React imports
  • Add type declaration for the virtual module
  • Document the new option in API docs
  • Add e2e tests to verify execution timing

Usage

// vite.config.ts
funstackStatic({
  root: "./src/root.tsx",
  app: "./src/App.tsx",
  clientInit: "./src/client-init.ts", // optional
})

// src/client-init.ts - Side effects only, no exports needed
import * as Sentry from "@sentry/browser";

Sentry.init({
  dsn: "https://your-sentry-dsn",
  environment: import.meta.env.MODE,
});

Test plan

  • Build succeeds (pnpm build)
  • E2e tests pass (pnpm test:e2e)
  • Verified clientInit runs before React hydration via timestamp comparison

🤖 Generated with Claude Code

uhyo and others added 2 commits February 1, 2026 17:22
Add a new optional `clientInit` configuration option that allows users
to specify a module that runs on the client side before React hydration.
This enables client-side instrumentation like Sentry, analytics, or
feature flags.

- Add `clientInit?: string` to FunstackStaticOptions interface
- Add `virtual:funstack/client-init` virtual module handling
- Import client-init at top of client entry before React
- Add type declaration for the virtual module
- Document the new option in API docs
- Add e2e tests to verify execution timing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@uhyo uhyo merged commit b42cd71 into master Feb 1, 2026
1 check passed
@uhyo uhyo deleted the feat/client-init branch February 1, 2026 08:24
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.

1 participant