Skip to content

Storybook: Add a note for agents that read the page without JavaScript - #85757

Merged
mirka merged 4 commits into
trunkfrom
storybook-agent-docs-note
Oct 28, 2026
Merged

mirka merged 4 commits into
trunkfrom
storybook-agent-docs-note

Conversation

@mirka

@mirka mirka commented Oct 27, 2026

Copy link
Copy Markdown
Member

What?

Follow up to #85752 (comment).

Add a note to the Storybook page that tells AI agents and other tools without JavaScript where to read the documentation.

Why?

Storybook links, such as those in use-recommended-components lint messages, are not useful to AI agents. Fetching https://wordpress.github.io/gutenberg/?path=/docs/components-checkboxcontrol--migration-guide without JavaScript returns only the page title "storybook - Storybook". The documentation is available in machine-readable form, but nothing on the page says where.

How?

A post-build script adds the note inside the manager's root element in index.html. The note points to the Design System MCP server, to index.json and how to map a page's path parameter to its source file on GitHub, and to manifests/components.json.

The note is hidden with CSS, and the manager replaces it when it renders, so the page looks the same in a browser. Tools that convert HTML to text do not apply stylesheets, so they still read it. I put the note in the root element instead of <noscript> because some of these tools skip <noscript> content. Turndown, node-html-markdown, html-to-text, Readability, html2text, and markdownify all include the note in their output.

Testing Instructions

  1. Run npm run storybook:build.
  2. Confirm that storybook/build/index.html contains the note inside <div id="root">.
  3. Serve storybook/build and open it in a browser. Confirm that Storybook loads as before and that the note is not visible, including while the page loads.

@mirka mirka added the [Type] Developer Documentation Documentation for developers label Oct 27, 2026
@mirka mirka self-assigned this Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: 0 B

Total Size: 8.56 MB

4ee7e8c Run

@mirka

mirka commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

@aduth I tried to see if I could test the efficacy of this strategy locally, but the several sets of tests I could run were inconclusive, mainly because:

  • Agents are quite resourceful, so they can actually figure out a lot even without access to the rendered Storybook pages. I first ran "control" cases with relatively low-intelligence models (Haiku and Luna), and they are already able to get what they need through the Storybook JS bundles, source files on GitHub/unpkg, etc. Sometimes even through the original PRs on GitHub!
  • In the second round of more isolated tests, I tried to set up a "realistic" situation with a local Storybook server with a fake certificate and an eslint error to fix. That failed too, presumably because the agents were suspicious of the URL. In more than 20 runs, none of the agents dared open the fake guide link, while they were fine opening an actual wordpress.github.io link 😅

So I think we might have to test after deploy, and tweak or revert if there's no measurable difference. Worth trying?

@aduth

aduth commented Oct 27, 2026

Copy link
Copy Markdown
Member

I think it's worth testing! I had actually explored something nearly identical in the past, and came to a few related conclusions / observations:

  • The issue of content being unreadable extends to anything that doesn't render JavaScript, such as JavaScript-disabled browsers
  • Agents may be particularly wary of prompt injection, and targeted language telling them what to do may be blocked
  • With those two points in mind, writing it like this as far as where to find additional resources without targeting AI specifically or telling it to take specific actions (like installing the MCP server) is likely the safer bet

The only remaining concerns I had / have are:

  • Whether there's any risk of flash of content before the content is replaced with JavaScript-rendered contents, and whether there's a better way of presenting it (e.g. <noscript>, or inline styles, and which styles specifically to hide the content)
  • components.json could be a valuable resource, but it's also quite large, and I don't know how well agents would tolerate its full download size. In the future the shape of the manifest will change and it will be much more compact by default, linking out to related resources. So maybe it's fine to point to it, with an understanding that it may or may not be used in the short term, and more useful later on. I imagine an agent might still be able to use it today but it'd probably download it to some local directory and parse it with a tool like jq, and those additional steps might be enough burden for it to just not bother.

Comment on lines +17 to +18
const rawBaseUrl =
'https://raw.githubusercontent.com/WordPress/gutenberg/trunk';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have a constant we can use instead? I suppose this likely won't change though so maybe not worth dwelling on.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unfortunately not.

Comment on lines +20 to +22
const style = '<style>#agent-docs-note { display: none; }</style>';

const note = `<div id="agent-docs-note">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this be an inline style?

Suggested change
const style = '<style>#agent-docs-note { display: none; }</style>';
const note = `<div id="agent-docs-note">
const note = `<div style="display: none">

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried the inline style, but Mozilla Readability skips elements with an inline display: none, so the note disappeared from its output. A <style> rule in <head> hides it before the first paint just as well, and all six HTML-to-text tools I tested kept the note with it. I added a comment explaining this.

@aduth

aduth commented Oct 27, 2026

Copy link
Copy Markdown
Member

I had actually explored something nearly identical in the past

Trying to track this down, it was a local-only exploration I had, and it falls outside my Claude default retention window. I managed to salvage some metadata (my own prompting) to piece together some additional context, some of which mentioned already:

September 4. You narrowed it to generic <noscript> text for any client that cannot run JavaScript, and you did not want an “install the MCP” command in that text because it could read as prompt injection. The intended outcome was awareness: use the MCP if it is already installed, otherwise tell the person, and link somewhere to learn more. You then worried the text would flash for browsers that do run JavaScript, that the implementation had grown past a hundred lines, and whether Storybook has a built-in place for this instead of an injection that a future version could break.

@mirka

mirka commented Oct 28, 2026

Copy link
Copy Markdown
Member Author

Thanks, this matches what I saw. On flash: the note is hidden by a stylesheet in <head>, so it is hidden before the first paint, and the manager replaces it on mount. I checked in Chromium that it is never visible.

I compared six HTML-to-text tools (Turndown, node-html-markdown, html-to-text, Readability, html2text, markdownify). <noscript> in the body was dropped by node-html-markdown and Readability, and an inline display: none was dropped by Readability. The stylesheet version was kept by all six, so I'd like to keep it.

Agreed on components.json. I'll keep the link with the expectation that it gets more useful once the manifest is more compact.

I also ran fresh agents in an empty project with only the lint message. Haiku opened the wordpress.github.io link in 4 of 5 runs and got only the page title, then fell back to reading types on unpkg and GitHub. Luna never fetched the page. So the note only helps agents that open the page. Adding a link to the guide's source on GitHub to the lint message itself would probably reach more of them. It's unfortunate that we don't yet have a clean separation between human-facing lint messages and agent-facing ones. That could be quite useful.

@mirka

mirka commented Oct 28, 2026

Copy link
Copy Markdown
Member Author

I managed to salvage some metadata (my own prompting) to piece together some additional context, some of which mentioned already

Right, I think we're covered.

Storybook's manager template only has a head injection point (managerHead), so there's no built-in place for body content. To limit the breakage risk, the script asserts that </head> and <div id="root"></div> exist, so a template change fails the build instead of silently dropping the note. It's under 50 lines, and the MCP line describes the server and links its README without asking anyone to install it.

@mirka
mirka marked this pull request as ready for review October 28, 2026 08:35
@mirka mirka added the Storybook Storybook and its stories for components label Oct 28, 2026
@mirka
mirka enabled auto-merge (squash) October 28, 2026 08:38
@mirka
mirka merged commit 88d8457 into trunk Oct 28, 2026
79 checks passed
@mirka
mirka deleted the storybook-agent-docs-note branch October 28, 2026 08:52
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 28, 2026
@aduth

aduth commented Oct 28, 2026

Copy link
Copy Markdown
Member

Couple related links for posterity:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Storybook Storybook and its stories for components [Type] Developer Documentation Documentation for developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants