Skip to content

fix(KNO-14012): inject guide toolbar styles at runtime#1043

Open
thomaswhyyou wants to merge 1 commit into
mainfrom
thomas-kno-14012-investigate-bundling-css-import-into-toolbar
Open

fix(KNO-14012): inject guide toolbar styles at runtime#1043
thomaswhyyou wants to merge 1 commit into
mainfrom
thomas-kno-14012-investigate-bundling-css-import-into-toolbar

Conversation

@thomaswhyyou

@thomaswhyyou thomaswhyyou commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

Currently the guide Toolbar has an implicit dependency on @knocklabs/react/dist/index.css, because the toolbar component uses Telegraph components and it requires the telegraph styles to be present in the document.

If you happen to be not using any of the renderable components from @knocklabs/react, then you have no need for dist/index.css in your project. With guides, for example, if you are only using your custom guide components and not any of the OOTB components, then you don't need import dist/index.css.

One exception here though is the guide toolbar because the component needs certain telegraph and other styles. Currently we flag in the doc to import dist/index.css when using the toolbar, but it's a friction Neo4j have flagged.

This PR explores adding useToolbarStyles hook that inlines the telegraph css + other styles needed for the toolbar, and injects into the page when the toolbar is used. This adds ~21KB min/~5KB gzip of inline css to the bundle (~2% of the overall size), and in return removing the dependency on @knocklabs/react/dist/index.css.

TODO: Update the doc if/when we merge this.

@linear-code

linear-code Bot commented Jul 20, 2026

Copy link
Copy Markdown

KNO-14012

@changeset-bot

changeset-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b1a58af

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@knocklabs/react Patch
ms-teams-connect-example Patch
nextjs-app-dir-example Patch
slack-connect-example Patch
slack-kit-example Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
javascript-ms-teams-connect-example Ready Ready Preview, Comment Jul 20, 2026 10:25pm
javascript-nextjs-example Ready Ready Preview, Comment Jul 20, 2026 10:25pm
javascript-slack-connect-example Ready Ready Preview, Comment Jul 20, 2026 10:25pm
javascript-slack-kit-example Ready Ready Preview, Comment Jul 20, 2026 10:25pm

Request Review

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 43.74kB (7.62%) ⬆️⚠️, exceeding the configured threshold of 5%.

Bundle name Size Change
@knocklabs/react-react-esm 138.95kB 21.84kB (18.65%) ⬆️⚠️
@knocklabs/react-react-cjs 128.93kB 21.9kB (20.46%) ⬆️⚠️

Affected Assets, Files, and Routes:

view changes for bundle: @knocklabs/react-react-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
modules/guide/components/Toolbar/styles.css2.mjs (New) 21.35kB 21.35kB 100.0% 🚀
modules/guide/components/Toolbar/V2/V2.mjs 100 bytes 8.32kB 1.22%
modules/guide/components/Toolbar/useToolbarStyles.mjs (New) 389 bytes 389 bytes 100.0% 🚀

Files in modules/guide/components/Toolbar/V2/V2.mjs:

  • ./src/modules/guide/components/Toolbar/V2/V2.tsx → Total Size: 9.65kB

Files in modules/guide/components/Toolbar/useToolbarStyles.mjs:

  • ./src/modules/guide/components/Toolbar/useToolbarStyles.ts → Total Size: 409 bytes
view changes for bundle: @knocklabs/react-react-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
modules/guide/components/Toolbar/styles.css2.js (New) 21.35kB 21.35kB 100.0% 🚀
modules/guide/components/Toolbar/V2/V2.js 81 bytes 6.84kB 1.2%
modules/guide/components/Toolbar/useToolbarStyles.js (New) 473 bytes 473 bytes 100.0% 🚀

Files in modules/guide/components/Toolbar/V2/V2.js:

  • ./src/modules/guide/components/Toolbar/V2/V2.tsx → Total Size: 10.53kB

Files in modules/guide/components/Toolbar/useToolbarStyles.js:

  • ./src/modules/guide/components/Toolbar/useToolbarStyles.ts → Total Size: 410 bytes

@thomaswhyyou
thomaswhyyou requested review from a team, andy-knock, cjbell, connorlindsey, kylemcd and meryldakin and removed request for a team July 20, 2026 22:16
The guide toolbar rendered unstyled unless the consuming app imported
@knocklabs/react/dist/index.css, which apps rendering only custom guide
components have no reason to do. The toolbar now injects its compiled
styles (telegraph tokens + components + toolbar keyframes, via a ?inline
css import) into the document head when it becomes visible, so it works
without an explicit CSS import. dist/index.css is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@thomaswhyyou
thomaswhyyou force-pushed the thomas-kno-14012-investigate-bundling-css-import-into-toolbar branch from 4924b4e to b1a58af Compare July 20, 2026 22:23

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b1a58af. Configure here.

@@ -0,0 +1,21 @@
import React from "react";

import toolbarStyles from "./styles.css?inline";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Inline CSS stripped by build

High Severity

useToolbarStyles imports toolbar CSS via styles.css?inline, but the React package build deletes all *.css.js / *.css.mjs artifacts and strips CSS requires. With vite-plugin-no-bundle (preserveModules), that inline module is emitted as one of those files, so the published package loses the style string and runtime injection cannot work.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b1a58af. Configure here.

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.58%. Comparing base (3473c2a) to head (b1a58af).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1043      +/-   ##
==========================================
+ Coverage   66.02%   66.58%   +0.55%     
==========================================
  Files         213      214       +1     
  Lines       10500    10514      +14     
  Branches     1509     1529      +20     
==========================================
+ Hits         6933     7001      +68     
+ Misses       3542     3487      -55     
- Partials       25       26       +1     
Files with missing lines Coverage Δ
...act/src/modules/guide/components/Toolbar/V2/V2.tsx 27.05% <100.00%> (+16.95%) ⬆️
...dules/guide/components/Toolbar/useToolbarStyles.ts 100.00% <100.00%> (ø)

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