-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Core: Restore useParameter
behaviour for Docs entries
#22071
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work. I have questions though...
@@ -113,6 +119,10 @@ function removeRemovedOptions<T extends Record<string, any> = Record<string, any | |||
return result; | |||
} | |||
|
|||
function toComponentId(storyId: StoryId): ComponentId { | |||
return storyId.split('--')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a little surprised we don't have a utility in @storybok/csf
for this. no big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too. I didn't want to mess around with new CSF packages at this moment in time, but can if you disagree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open a PR for this against the CSF package, but don't merge
} | ||
} | ||
|
||
// If not prepared, or a unattached doc, get the project's parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens in the case it's not prepared? is there a race condition here? or is it handled somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok read more of the PR and it looks like COMPONENT_PREPARED
is emitted in the story render or the CSF Docs render. Are there other cases that need to be accounted for?
@@ -745,6 +790,13 @@ describe('PreviewWeb', () => { | |||
expect(importFn).toHaveBeenCalledWith('./src/ComponentTwo.stories.js'); | |||
}); | |||
|
|||
it('DOES NOT emit COMPONENT_PREPARED', async () => { | |||
document.location.search = '?id=introduction--docs&viewMode=docs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the component parameters wouldn't show in this case? Seems inconsistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no "component parameters" in this case as it is a MDX file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should emit the project parameters here.
@@ -29,6 +29,8 @@ import { DocsContext } from '../docs-context/DocsContext'; | |||
export class MdxDocsRender<TRenderer extends Renderer> implements Render<TRenderer> { | |||
public readonly type: RenderType = 'docs'; | |||
|
|||
public readonly subtype = 'mdx'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess in this case, it would not emit a COMPONENT_PREPARED
.. but does that mean that the store is in a perpetually unprepared state?
@@ -45,6 +45,7 @@ const Main: FC<{ provider: Provider }> = ({ provider }) => { | |||
docsOptions={global?.DOCS_OPTIONS || {}} | |||
> | |||
{({ state, api }: Combo) => { | |||
console.log(useParameter('backgrounds')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log(useParameter('backgrounds')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! only a few minor requests
@tmeasday thanks for working on this! |
Closes #21798
What I did
PROJECT_PREPARED
andCOMPONENT_PREPARED
, analogous toSTORY_PREPARED
.argTypes
andparameters
) at appropriate times for components and the project.index
(both for local + refs), similar to the story annotationsgetParameter
(useParameter
) to fall back to the component then the project if parameters are not available.This means attached docs use the component's parameters -- in particular it means certain toolbars (backgrounds in essentials) appear again:
And unattached docs use the project's:
What I didn't do, but could in future:
state.projectAnnotations
andref.projectAnnotations
. This, plus an update togetGlobals[Types]
would address Composite Storybook does not show toolbars for the other storybooks #17759.A. Additional to this we should probably refactor the
SET_GLOBALS
event to just be part ofPROJECT_PREPARED
.argTypes
useful without initial args?storybook/code/lib/manager-api/src/modules/stories.ts
Lines 435 to 442 in be000bb
How to test
Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:merged
orci:daily
GH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]