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

Core: Show "booting" progress until story is specified or errors #20425

Merged
merged 34 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2341c67
Show a "booting" progress message until the story is specified
tmeasday Dec 28, 2022
91a431a
Apply suggestions from code review
tmeasday Dec 29, 2022
4cdecb9
Don't show a progressbar if booting
tmeasday Dec 29, 2022
38fcce2
Simplify things further
tmeasday Dec 29, 2022
e91aa76
Simplify a little
tmeasday Dec 29, 2022
8756b5d
Simplify
tmeasday Dec 29, 2022
9d2a9b5
Add some comments to explain things
tmeasday Jan 2, 2023
8f60c3d
Remove `storiesConfigured` et al, and simply to just `ready`.
tmeasday Jan 3, 2023
7ec1104
Show docs immediately on first load
tmeasday Jan 3, 2023
5575b4d
Don't set ready until we are actually ready!
tmeasday Jan 8, 2023
b839502
Change refs + stories to use a common interface
tmeasday Jan 11, 2023
5f105af
Drop some logs
tmeasday Jan 11, 2023
1714df8
Update tests
tmeasday Jan 12, 2023
4052c46
Missed this
tmeasday Jan 12, 2023
242a87b
Update snapshots
tmeasday Jan 12, 2023
93e9558
Update various tests/stories
tmeasday Jan 12, 2023
6ebf577
One more
tmeasday Jan 12, 2023
68f1975
Merge remote-tracking branch 'origin/next' into tom/sb-1123-sb20250-v…
tmeasday Jan 12, 2023
7358d55
Merge branch 'next' into tom/sb-1123-sb20250-vite-does-not-show-a-spi…
ndelangen Jan 12, 2023
48828c7
make changes to typings files to ensure this the check command succeeds
ndelangen Jan 12, 2023
4ed7408
Update stories->index and add back-compatibility
tmeasday Jan 13, 2023
d6fa356
Merge branch 'tom/sb-1123-sb20250-vite-does-not-show-a-spinner-2' of …
tmeasday Jan 13, 2023
24f35c5
Various updates
tmeasday Jan 13, 2023
0ae65e8
More fixes
tmeasday Jan 13, 2023
668565a
Fix up app stories to be initialized
tmeasday Jan 13, 2023
b25ec31
Bunch of updates I missed
tmeasday Jan 13, 2023
f5dba59
Missed one more
tmeasday Jan 13, 2023
996fdde
Even more fixes
tmeasday Jan 13, 2023
39f5da8
Another issue
tmeasday Jan 13, 2023
c65b8ab
Catch missing stories
tmeasday Jan 13, 2023
02cee42
Add debugging to built-in sb
tmeasday Jan 13, 2023
dead68d
Merge pull request #20598 from storybookjs/norbert/make-typescript-ch…
ndelangen Jan 13, 2023
d972473
Merge branch 'next' into tom/sb-1123-sb20250-vite-does-not-show-a-spi…
ndelangen Jan 18, 2023
f3bfca4
when testing for regressions, this didn't show up at all. renaming it…
ndelangen Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions code/lib/manager-api/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import type {
API_DocsEntry,
API_GroupEntry,
API_HashEntry,
API_IndexHash,
API_LeafEntry,
API_OptionsData,
API_ProviderData,
API_Refs,
API_RootEntry,
API_StateMerger,
API_StoriesHash,
API_StoryEntry,
Parameters,
StoryId,
Expand Down Expand Up @@ -326,7 +326,9 @@ export function useStorybookApi(): API {
}

export type {
API_StoriesHash as StoriesHash,
/** @deprecated now IndexHash */
API_IndexHash as StoriesHash,
API_IndexHash as IndexHash,
API_RootEntry as RootEntry,
API_GroupEntry as GroupEntry,
API_ComponentEntry as ComponentEntry,
Expand Down
14 changes: 7 additions & 7 deletions code/lib/manager-api/src/lib/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
API_RootEntry,
API_GroupEntry,
API_ComponentEntry,
API_StoriesHash,
API_IndexHash,
API_DocsEntry,
API_StoryEntry,
API_HashEntry,
Expand Down Expand Up @@ -122,7 +122,7 @@ export const transformStoryIndexToStoriesHash = (
provider: API_Provider<API>;
docsOptions: DocsOptions;
}
): API_StoriesHash => {
): API_IndexHash => {
if (!index.v) throw new Error('Composition: Missing stories.json version');

const v4Index = index.v === 4 ? index : transformStoryIndexV3toV4(index as any);
Expand Down Expand Up @@ -241,10 +241,10 @@ export const transformStoryIndexToStoriesHash = (
} as API_DocsEntry | API_StoryEntry;

return acc;
}, {} as API_StoriesHash);
}, {} as API_IndexHash);

// This function adds a "root" or "orphan" and all of its descendents to the hash.
function addItem(acc: API_StoriesHash, item: API_HashEntry) {
function addItem(acc: API_IndexHash, item: API_HashEntry) {
// If we were already inserted as part of a group, that's great.
if (acc[item.id]) {
return acc;
Expand All @@ -268,7 +268,7 @@ export const transformStoryIndexToStoriesHash = (
.reduce(addItem, orphanHash);
};

export const addPreparedStories = (newHash: API_StoriesHash, oldHash?: API_StoriesHash) => {
export const addPreparedStories = (newHash: API_IndexHash, oldHash?: API_IndexHash) => {
if (!oldHash) return newHash;

return Object.fromEntries(
Expand All @@ -283,7 +283,7 @@ export const addPreparedStories = (newHash: API_StoriesHash, oldHash?: API_Stori
);
};

export const getComponentLookupList = memoize(1)((hash: API_StoriesHash) => {
export const getComponentLookupList = memoize(1)((hash: API_IndexHash) => {
return Object.entries(hash).reduce((acc, i) => {
const value = i[1];
if (value.type === 'component') {
Expand All @@ -293,6 +293,6 @@ export const getComponentLookupList = memoize(1)((hash: API_StoriesHash) => {
}, [] as StoryId[][]);
});

export const getStoriesLookupList = memoize(1)((hash: API_StoriesHash) => {
export const getStoriesLookupList = memoize(1)((hash: API_IndexHash) => {
return Object.keys(hash).filter((k) => ['story', 'docs'].includes(hash[k].type));
});
28 changes: 14 additions & 14 deletions code/lib/manager-api/src/modules/refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
API_Refs,
API_SetRefData,
SetStoriesStoryData,
API_StoriesHash,
API_IndexHash,
API_StoryMapper,
} from '@storybook/types';
// eslint-disable-next-line import/no-cycle
Expand All @@ -33,7 +33,7 @@ export interface SubAPI {
getRefs: () => API_Refs;
checkRef: (ref: API_SetRefData) => Promise<void>;
changeRefVersion: (id: string, url: string) => void;
changeRefState: (id: string, ready: boolean) => void;
changeRefState: (id: string, previewInitialized: boolean) => void;
}

export const getSourceType = (source: string, refId: string) => {
Expand All @@ -56,10 +56,10 @@ export const defaultStoryMapper: API_StoryMapper = (b, a) => {
return { ...a, kind: a.kind.replace('|', '/') };
};

const addRefIds = (input: API_StoriesHash, ref: API_ComposedRef): API_StoriesHash => {
const addRefIds = (input: API_IndexHash, ref: API_ComposedRef): API_IndexHash => {
return Object.entries(input).reduce((acc, [id, item]) => {
return { ...acc, [id]: { ...item, refId: ref.id } };
}, {} as API_StoriesHash);
}, {} as API_IndexHash);
};

async function handleRequest(
Expand All @@ -83,8 +83,8 @@ async function handleRequest(
}

return json as API_SetRefData;
} catch (error) {
return { error };
} catch (err) {
return { indexError: err };
}
}

Expand Down Expand Up @@ -139,10 +139,10 @@ export const init: ModuleFn<SubAPI, SubState, void> = (

api.checkRef(ref);
},
changeRefState: (id, ready) => {
changeRefState: (id, previewInitialized) => {
const { [id]: ref, ...updated } = api.getRefs();

updated[id] = { ...ref, ready };
updated[id] = { ...ref, previewInitialized };

store.setState({
refs: updated,
Expand Down Expand Up @@ -205,7 +205,7 @@ export const init: ModuleFn<SubAPI, SubState, void> = (
// In theory the `/iframe.html` could be private and the `stories.json` could not exist, but in practice
// the only private servers we know about (Chromatic) always include `stories.json`. So we can tell
// if the ref actually exists by simply checking `stories.json` w/ credentials.
loadedData.error = {
loadedData.indexError = {
message: dedent`
Error: Loading of ref failed
at fetch (lib/api/src/modules/refs.ts)
Expand Down Expand Up @@ -245,18 +245,18 @@ export const init: ModuleFn<SubAPI, SubState, void> = (
const { storyMapper = defaultStoryMapper } = provider.getConfig();
const ref = api.getRefs()[id];

let storiesHash: API_StoriesHash;
let index: API_IndexHash;
if (setStoriesData) {
storiesHash = transformSetStoriesStoryDataToStoriesHash(
index = transformSetStoriesStoryDataToStoriesHash(
map(setStoriesData, ref, { storyMapper }),
{ provider, docsOptions }
);
} else if (storyIndex) {
storiesHash = transformStoryIndexToStoriesHash(storyIndex, { provider, docsOptions });
index = transformStoryIndexToStoriesHash(storyIndex, { provider, docsOptions });
}
if (storiesHash) storiesHash = addRefIds(storiesHash, ref);
if (index) index = addRefIds(index, ref);

api.updateRef(id, { stories: storiesHash, ...rest, ready });
api.updateRef(id, { index, ...rest });
},

updateRef: (id, data) => {
Expand Down