8000 GitHub - JReinhold/storybook-tanstack-server-repro · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

TanStack Start Storybook Reproduction

This repository is a reduced reproduction for a TanStack Start + Storybook bug.

Problem

When a TanStack Start server function module defines a helper outside createServerFn(...).handler(), Storybook keeps the node:crypto import in the browser bundle instead of tree-shaking it away.

When the same logic is moved inline into the handler, Storybook no longer reports the browser-compatibility warning.

Reproduction Files

  • Broken server function: src/server/storybook/broken.functions.ts
  • Working server function: src/server/storybook/works.functions.ts
  • Broken Storybook story: src/stories/Broken.stories.tsx
  • Working Storybook story: src/stories/Works.stories.tsx
  • Shared app route: src/routes/index.tsx

Steps To Reproduce

  1. Install dependencies.

    npm install
  2. Build Storybook.

    npm run build-storybook
  3. Observe the Storybook build output.

Actual Behavior

Storybook emits a browser-compatibility warning for the broken flow:

Module "node:crypto" has been externalized for browser compatibility, imported by
".../src/server/storybook/broken.functions.ts".

The broken story still builds, but it demonstrates that the hoisted helper is not removed from the client-side Storybook bundle.

Expected Behavior

Storybook should tree-shake server-only code in TanStack Start server function modules the same way TanStack Start does in the normal application build, regardless of whether the helper is declared outside the handler or inline within it.

At minimum, the broken flow should not pull node:crypto into the browser-side Storybook bundle.

Control Case

The working control case moves the fingerprint logic inline inside the handler:

  • src/server/storybook/works.functions.ts

That version does not trigger the node:crypto browser warning during Storybook build.

App Control

The normal TanStack Start application route at src/routes/index.tsx renders both flows and builds successfully, showing that the behavior difference is specific to the Storybook integration path.

Verification Commands

TypeScript check:

./node_modules/.bin/tsc --noEmit --pretty false

App build:

./node_modules/.bin/vite build --debug --clearScreen false

Storybook build:

./node_modules/.bin/storybook build

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0