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

Addon-docs: Improved loading state #16709

Merged
merged 14 commits into from Nov 22, 2021
Merged

Addon-docs: Improved loading state #16709

merged 14 commits into from Nov 22, 2021

Conversation

tmeasday
Copy link
Member

@tmeasday tmeasday commented Nov 17, 2021

What I did

Improvements to docs loading state.

Still TODO

  • Final UI tweaks from @MichaelArestad
  • Rationalization of loading props @tmeasday
  • Investigate flickering of preview component @tmeasday
  • Investigate components rendering whilst still "preparing" @tmeasday
  • Fix stories to render consistently in chromatic

How to test

  • Is this testable with Jest or Chromatic screenshots?
  • Does this need a new example in the kitchen sink apps?
    Yes, see examples in PR

@nx-cloud
Copy link

nx-cloud bot commented Nov 17, 2021

Nx Cloud Report

CI ran the following commands for commit d3a4b08. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch

Status Command
#000000 nx run-many --target=prepare --all --parallel --max-parallel=15

Sent with 💌 from NxCloud.

@shilman
Copy link
Member

shilman commented Nov 19, 2021

I'm getting this error when I click on react-ts AccountForm stories in docs mode, but I'm not seeing it in the built storybook for next (haven't investigated whether this is an issue with dev mode or with the branch)

Demo___Account_Form_-_Standard_⋅_Storybook_and_Demo___Account_Form_-_Standard_⋅_Storybook

@tmeasday
Copy link
Member Author

tmeasday commented Nov 19, 2021

@shilman

I'm getting this error when I click on react-ts AccountForm stories in docs mode, but I'm not seeing it in the built storybook for next (haven't investigated whether this is an issue with dev mode or with the branch)

I'm pretty sure this problem is caused by this code:

const handleSnippetRendered = (id: StoryId, newItem: SourceItem) => {
if (newItem !== sources[id]) {
setSources((current) => {
const newSources = { ...current, [id]: newItem };
if (!deepEqual(current, newSources)) {
return newSources;
}
return current;
});
}
};
channel.on(SNIPPET_RENDERED, handleSnippetRendered);
return () => channel.off(SNIPPET_RENDERED, handleSnippetRendered);
});

Perhaps we should revert it to the version that we have on main given I think we only changed it for reasons that we later reverted? I don't remember, anyway you can see the version on main is doing complex stuff to avoid this problem:

const sourcesRef = React.useRef<StorySources>();
const handleSnippetRendered = (id: StoryId, newItem: SourceItem) => {
if (newItem !== sources[id]) {
const newSources = { ...sourcesRef.current, [id]: newItem };
sourcesRef.current = newSources;
}
};
// Bind this early (instead of inside `useEffect`), because the `SNIPPET_RENDERED` event
// is triggered *during* the rendering process, not after. We have to use the ref
// to ensure we don't end up calling setState outside the effect though.
channel.on(SNIPPET_RENDERED, handleSnippetRendered);
useEffect(() => {
const current = sourcesRef.current || {};
if (!deepEqual(sources, current)) {
setSources(current);
}
return () => channel.off(SNIPPET_RENDERED, handleSnippetRendered);
});

@shilman shilman changed the title Docs loading state (v2) Addon-docs: Improved loading state Nov 22, 2021
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

LGTM!

@shilman shilman merged commit ffd73a1 into next Nov 22, 2021
@shilman shilman deleted the docs-loading-state branch November 22, 2021 03:40
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.

None yet

3 participants