Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Type of canvasElement from getStoryContext is unknown #436

Closed
unional opened this issue Mar 5, 2024 · 2 comments · Fixed by #462
Closed

[Bug]: Type of canvasElement from getStoryContext is unknown #436

unional opened this issue Mar 5, 2024 · 2 comments · Fixed by #462
Labels
bug Something isn't working needs triage

Comments

@unional
Copy link

unional commented Mar 5, 2024

Describe the bug

import { getStoryContext } from "@storybook/test-runner"

// in postVisit
const storyContext = await getStoryContext(page, context)
storyContext.canvasElement // type unknown should be HTMLElement

This is caused by:

interfact StoryContext<TRenderer extends Renderer = Renderer, ...> ... {

  canvasElement: TRenderer['canvasElement']
}

type Renderer = {
  canvasElement: unknown
}

To Reproduce

No response

System

Not applicable

Additional context

No response

@unional unional added bug Something isn't working needs triage labels Mar 5, 2024
@unional
Copy link
Author

unional commented Mar 5, 2024

Note that in both preVisit and postVisit the value of canvasElement is undefined at runtime.
Not sure if that is intentional or it's a bug. In either way the type and runtime doesn't match.

@valentinpalkovic valentinpalkovic transferred this issue from storybookjs/storybook Mar 6, 2024
@yannbf
Copy link
Member

yannbf commented May 16, 2024

Hey @unional! Thanks for the report, I appreciate the question. The test-runner's getStoryContext function executes the following:

window.__STORYBOOK_PREVIEW__.storyStore.loadStory({ storyId: 'your-story-id-from-url-here' })

which is a core Storybook API, that resolves to something like this:
image

So I can see that it doesn't match StoryContext, but rather StoryContextForEnhancers. I'll make a fix for it! But keep in mind that this is mostly a Typescript fix, making the type more true to the actual return values, rather than having canvasElement available. In fact, even if canvasElement was available, you wouldn't be able to get it fully, as it's transported from Browser to Node by Playwright, and it would essentially give you something like { canvasElement: 'ref: <Node>' } rather than an actual DOM element.

@yannbf yannbf mentioned this issue May 16, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants