Skip to content

Storybook: Standardize stories on ServerItemRendererWithDebugUI - #4217

Open
jeremywiebe wants to merge 8 commits into
mainfrom
jer/story-decorator-consistency
Open

jeremywiebe wants to merge 8 commits into
mainfrom
jer/story-decorator-consistency

Conversation

@jeremywiebe

@jeremywiebe jeremywiebe commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

This PR adjusts stories to render widget stories with ServerItemRendererWithDebugUI instead of using smaller PerseusRenderers. It's mostly a bit of standardizing (ideally, I think having all our widgets approach building stories in the same, consistent way unless there's a real need to diverge).

This also preserves distinct answerful and answerless group and table stories.

Issue: LEMS-4592

Test plan

  • pnpm typecheck
  • pnpm lint
  • pnpm test

@github-actions

Copy link
Copy Markdown
Contributor

npm Snapshot

Want to try this PR's changes before it merges? Comment /snapshot below and we'll publish an npm snapshot you can install right away.

@jeremywiebe jeremywiebe changed the title ## Summary Standardize stories on QuestionRendererForStories Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Size Change: +11 B (0%)

Total Size: 499 kB

📦 View Changed
Filename Size Change
packages/perseus/dist/es/index.js 196 kB +11 B (+0.01%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.6 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 6.31 kB
packages/math-input/dist/es/index.js 98.5 kB
packages/math-input/dist/es/strings.js 1.63 kB
packages/perseus-core/dist/es/index.js 29.2 kB
packages/perseus-editor/dist/es/index.js 105 kB
packages/perseus-linter/dist/es/index.js 10.4 kB
packages/perseus-score/dist/es/index.js 9.91 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/strings.js 12.9 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.12 kB

compressed-size-action

@jeremywiebe
jeremywiebe marked this pull request as ready for review September 11, 2026 20:19
@jeremywiebe
jeremywiebe requested review from a team, handeyeco and nishasy September 11, 2026 20:19

export const Answerless: Story = {
args: {
item: getFullGroupTestItem(),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not so answerless after all. 😂

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.

Womp womp


export const Answerless: Story = {
args: {
item: getFullGroupTestItem(),

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.

Womp womp

args: {
item: generateTestPerseusItem({question: basicBlankQuestion}),
},
args: {question: basicBlankQuestion},

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.

I'm curious about the motivation here as the ticket and PR description didn't make it totally clear to me.

My gut reaction is that I personally would prefer us using an actual PerseusItem since like probably 90-99% of real world use of Perseus uses a PerseusItem.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I ran across this while doing some unrelated work on Chromatic... The motivation is that we are inconsistent in how we build stories for widgets. I much prefer using the smaller data structure and narrowed Renderer in these tests because we don't use any of the features that the ServerItemRenderer (SIR) provides. Although externally most of the world uses SIR, I don't think that's a great reason to use it here. Even if we eventually unify the external API to use SIR everywhere, I don't see us getting rid of Renderer.

That said, I could change this PR to unify usages in the opposite direction (use SIR for all widget stories) if you feel strongly. :)

@jeremywiebe
jeremywiebe force-pushed the jer/story-decorator-consistency branch from 2fef37f to 6dbd000 Compare September 16, 2026 00:01
@jeremywiebe jeremywiebe changed the title Standardize stories on QuestionRendererForStories Standardize stories on ServerItemRendererWithDebugUI Sep 16, 2026
@jeremywiebe
jeremywiebe changed the base branch from main to jer/debug-ui-toolbar-switches September 16, 2026 17:19
@jeremywiebe
jeremywiebe force-pushed the jer/story-decorator-consistency branch from d5f2883 to bec3e94 Compare September 16, 2026 17:26
@jeremywiebe jeremywiebe changed the title Standardize stories on ServerItemRendererWithDebugUI Storybook: Standardize stories on ServerItemRendererWithDebugUI Sep 16, 2026
options: generateCategorizerOptions({
...args,
<ServerItemRendererWithDebugUI
item={generateTestPerseusItem({

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.

I personally like separating out JSX from regular JS logic when the JS logic starts getting complex.

) => {
    const item = generateTestPerseusRenderer({
        // ...etc...
    })

    return (
        <ServerItemRendererWithDebugUI
            item={item}

Same note for a lot of these.

@jeremywiebe jeremywiebe Sep 17, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Don't know why but it doesn't bother me much...

I've refactored them to generate the item outside of the JSX elements.

alt: "Fresco painting",
longDescription: "long description",
<ServerItemRendererWithDebugUI
item={generateTestPerseusItem({

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.

OMG especially these. This is my nightmare fuel seeing all these item generation logic in JSX.

export const AnswerlessTable: Story = {
args: {
item: tableItem,
item: answerlessTableItem,

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.

Womp womp 2: the wompening

@jeremywiebe
jeremywiebe force-pushed the jer/debug-ui-toolbar-switches branch from 896bf75 to 00a84f1 Compare September 17, 2026 16:38
Base automatically changed from jer/debug-ui-toolbar-switches to main September 17, 2026 16:54
jeremywiebe added a commit that referenced this pull request Sep 17, 2026
## Summary:

Today, our widget stories, use a mix of `ServerItemRendererWithDebugUI` and `QuestionRendererForStories`. In #4217 I attempted to unify the component we use for all widget stories, but it hits Storybook `play` test failures. This is because the `ServerItemRendererWithDebugUI` has two switches in the header which are the first things that receive focus plus they add `switch` role elements to the DOM that confuse selection of elements. 

So, this PR moves these two debug header items to be true Storybook toolbar toggles. This removes them from the Storybook canvas and will eliminate the confounding elements for #4217.

<img width="311" height="172" alt="image" src="https://github.com/user-attachments/assets/007e525a-2f4d-49b8-920d-3a92e51575c3" />


Note that the Mobile toggle may not be what you think. It controls the `isMobile` flag that we pass to `apiOptions`. It's not a statement of viewport width (use the built-in Viewport Storybook toolbar item for that).  I've chosen _not_ to entwine these because you can have a wide viewport (tablet) and still have `isMobile` enabled and (unfortunately) you can have a narrow viewport (such as when Perseus is embedded in a narrow panel) and still have `isMobile: false`.

Issue: LEMS-4611 

## Test plan:

`pnpm start` 
Navigate to the [Dropdown](http://localhost:6006/?path=/story/widgets-dropdown-visual-regression-tests-initial-state--basic-dropdown) widget story. Change the mobile toggle and test. Chagne the Viewport widgth and test.

Author: jeremywiebe

Reviewers: handeyeco, jeremywiebe, benchristel, nishasy, mark-fitzgerald, ivyolamit, catandthemachines

Required Reviewers:

Approved By: handeyeco

Checks: ⏭️  2 checks have been skipped, ✅ 10 checks were successful

Pull Request URL: #4241
@jeremywiebe
jeremywiebe force-pushed the jer/story-decorator-consistency branch from 118ee5f to 2f9f6ee Compare September 17, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants