Skip to content

fix(storybook): resolve monorepo module aliases to raw source and prevent docgen AST crashes - #6274

Closed
VisheshDDev wants to merge 2 commits into
CopilotKit:mainfrom
VisheshDDev:fix/6089-virtual-scroll-jitter
Closed

VisheshDDev wants to merge 2 commits into
CopilotKit:mainfrom
VisheshDDev:fix/6089-virtual-scroll-jitter

Conversation

@VisheshDDev

Copy link
Copy Markdown

What does this PR do?

Resolves Storybook build failures and module resolution errors when running local development (pnpm dev) in examples/v2/react/storybook.

Root Causes Identified:

  1. Path Calculation: The path resolution in .storybook/main.ts was off by one directory hop (../../../../ instead of ../../.../../), placing resolution paths inside examples/ instead of the monorepo root.
  2. Startup Race Condition: Running tsdown --watch alongside Storybook deleted files in dist/v2 on startup, causing Module not found errors as Webpack tried to read them simultaneously.
  3. Docgen AST Crashes: Storybook's react-docgen attempted to parse minified .mjs build artifacts in packages/core/dist/, crashing the AST parser.

Key Changes:

  • Fixed relative directory math in .storybook/main.ts to cleanly target the packages/ root.
  • Updated @copilotkit/react-core/v2$ and @copilotkit/core$ Webpack aliases to point directly to raw TypeScript source files (src/v2/index.ts and src/index.ts).
  • Updated the stylesheet alias to point directly to src/v2/styles/globals.css.

Benefits:

  • Eliminates dist/ file deletion race conditions during concurrent watch tasks.
  • Shields react-docgen from bundled JavaScript while maintaining full auto-generated prop tables from TypeScript interfaces.
  • Enables instant Hot Module Replacement (HMR) for core framework source files.

Related PRs and Issues

Checklist

  • I have read the Contribution Guide
  • If the PR changes or adds functionality, I have updated the relevant documentation
  • "Allow edits by maintainers" is checked (lets us help iterate on your PR directly — faster turnaround for everyone)

@Aryankb

Aryankb commented Aug 7, 2026

Copy link
Copy Markdown

@tylerslaton @jpr5 @ranst91 @marthakelly @mme @BenTaylorDev @VisheshDDev
Are there any updates? We are using copilotkit in production and it would be really helpful if we can get a fix for issues
#6089 and #5979

Thanks!!

@Aryankb

Aryankb commented Aug 14, 2026 •

Copy link
Copy Markdown

Are there any updates? Thanks!

@pkg-pr-new

pkg-pr-new Bot commented Aug 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

@copilotkit/a2ui-renderer

pnpm add https://pkg.pr.new/@copilotkit/a2ui-renderer@6274

@copilotkit/agentcore-runner

pnpm add https://pkg.pr.new/@copilotkit/agentcore-runner@6274

@copilotkit/angular

pnpm add https://pkg.pr.new/@copilotkit/angular@6274

@copilotkit/channels

pnpm add https://pkg.pr.new/@copilotkit/channels@6274

@copilotkit/channels-core

pnpm add https://pkg.pr.new/@copilotkit/channels-core@6274

@copilotkit/channels-discord

pnpm add https://pkg.pr.new/@copilotkit/channels-discord@6274

@copilotkit/channels-intelligence

pnpm add https://pkg.pr.new/@copilotkit/channels-intelligence@6274

@copilotkit/channels-slack

pnpm add https://pkg.pr.new/@copilotkit/channels-slack@6274

@copilotkit/channels-teams

pnpm add https://pkg.pr.new/@copilotkit/channels-teams@6274

@copilotkit/channels-telegram

pnpm add https://pkg.pr.new/@copilotkit/channels-telegram@6274

@copilotkit/channels-ui

pnpm add https://pkg.pr.new/@copilotkit/channels-ui@6274

@copilotkit/channels-whatsapp

pnpm add https://pkg.pr.new/@copilotkit/channels-whatsapp@6274

@copilotkit/core

pnpm add https://pkg.pr.new/@copilotkit/core@6274

@copilotkit/react-core

pnpm add https://pkg.pr.new/@copilotkit/react-core@6274

@copilotkit/react-native

pnpm add https://pkg.pr.new/@copilotkit/react-native@6274

@copilotkit/react-textarea

pnpm add https://pkg.pr.new/@copilotkit/react-textarea@6274

@copilotkit/react-ui

pnpm add https://pkg.pr.new/@copilotkit/react-ui@6274

@copilotkit/runtime

pnpm add https://pkg.pr.new/@copilotkit/runtime@6274

@copilotkit/runtime-client-gql

pnpm add https://pkg.pr.new/@copilotkit/runtime-client-gql@6274

@copilotkit/sdk-js

pnpm add https://pkg.pr.new/@copilotkit/sdk-js@6274

@copilotkit/shared

pnpm add https://pkg.pr.new/@copilotkit/shared@6274

@copilotkit/sqlite-runner

pnpm add https://pkg.pr.new/@copilotkit/sqlite-runner@6274

@copilotkit/voice

pnpm add https://pkg.pr.new/@copilotkit/voice@6274

@copilotkit/vue

pnpm add https://pkg.pr.new/@copilotkit/vue@6274

@copilotkit/web-components

pnpm add https://pkg.pr.new/@copilotkit/web-components@6274

@copilotkit/web-inspector

pnpm add https://pkg.pr.new/@copilotkit/web-inspector@6274

commit: bd3ece1

@BenTaylorDev BenTaylorDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, and sorry for the slow reply here.

This bundles two unrelated changes, and I have findings on both. I would like to see them split.

1. The getItemKey change duplicates a PR I already closed

getItemKey: (index) => deduplicatedMessages[index]!.id in CopilotChatMessageView.tsx is the same change as #6564, which I closed on 2026-08-21. The reasoning still applies: #6089 reports height-variance hopping, where long code blocks measure far above estimateSize: () => 100. getItemKey only re-keys the virtualizer's internal measurement cache, so it does not touch that mechanism. On an append-only chat, index keys and id keys agree.

The change is a genuine improvement on its own merits, because deduplicatedMessages can drop an entry mid-list and shift every later index. I am happy to take it as a standalone PR with a test, and without the Fixes #6089 link. If you do re-file it, please use deduplicatedMessages[index]?.id ?? index rather than the non-null assertion.

Leaving #6089 open.

2. The Storybook alias change removes every Tailwind utility

I built Storybook twice locally, once on main and once with this branch's .storybook/main.ts. Both builds succeed. The bundles differ:

main this PR
build result success success
compiled cpk: utility selectors 1332 0
.cpk\:flex, .cpk\:flex-col, ... present absent

The cause is this alias:

"@copilotkit/react-core/v2/styles.css": path.join(reactCorePkgPath, "src/v2/styles/globals.css"),

globals.css is a Tailwind v4 source file. Its first line is @import "tailwindcss" prefix(cpk);. The example has no postcss.config.* and no tailwindcss dependency, so nothing compiles it. Webpack inlines Tailwind's own index.css and emits zero utility classes. The build stays green and every story renders unstyled.

The alias also skips packages/react-core/scripts/scope-preflight.mjs, which scopes @layer base under [data-copilotkit] to stop CopilotKit styles leaking into the host page. That step runs as part of build:css and produces dist/v2/index.css, which is what the current alias-free setup already resolves through package exports.

Smaller notes on the same file

  • The stated root cause does not match the repo. The description says path resolution was off by one hop, from ../../../../. git log --all -S'../../../../' -- examples/v2/react/storybook/.storybook/main.ts returns exactly one commit, 1d367c635, which is this branch's own first commit. main.ts on main has never contained path math.
  • The dist race is narrowed, not eliminated. @copilotkit/shared, @copilotkit/web-inspector, and @copilotkit/web-components are imported from react-core v2 source and still resolve to dist, and the dev script still runs tsdown --watch.
  • console.log("React core package path:", reactCorePkgPath) prints on every startup. Please drop it.
  • The module.rules.map(...) block maps each rule to { ...rule } and returns everything else unchanged, so it is a no-op. Please drop it.
  • symlinks: true is already the webpack default.

What I am asking for

  1. Split the CopilotChatMessageView.tsx change into its own PR, with a test, and without the issue link.
  2. Drop the styles.css alias, or add a real Tailwind build for the example. Verify by grepping the built bundle for cpk\: selectors.
  3. Remove the console.log, the no-op module.rules block, and symlinks: true.
  4. Update the description so the root cause matches what is on main.

One note for anyone reading this while looking for a #6089 fix: this PR does not fix it, and the issue stays open.

@BenTaylorDev

Copy link
Copy Markdown
Contributor

Thanks for this, @VisheshDDev. Closing it, for the reasons in the 2026-09-02 review: the Storybook alias change removes every compiled cpk: utility, and neither change addresses the jitter in #6089. That jitter has since been fixed by #7243 (released in v1.74.0), which changed the virtualizer's size estimate and scroll correction. @Aryankb, that's the release to try for #6089.

The getItemKey change is still a worthwhile improvement on its own, and it isn't on main yet. If you'd like to re-file it as a standalone PR with a test (using deduplicatedMessages[index]?.id ?? index, and without the Fixes #6089 link), we'll review it.

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.

🐛 Bug: Virtual scrolling jitters badly with messages of varying heights

3 participants