Skip to content

First POC of how an app-level SB could function #1

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tmeasday
Copy link
Member

No description provided.

};

export const StorybookLayout = ({ children }) => {
const storyCookie = cookies().get('__storyId__');
Copy link
Member Author

@tmeasday tmeasday Feb 13, 2024

Choose a reason for hiding this comment

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

I had to use a cookie because you cannot read query params ("search params") in layouts AFAICT.

Perhaps there's some other way to run code on every request in Next. Maybe the redirect wasn't necessary and I could just do it in the middleware?

The challenge here is that middleware cannot import cache from react (which mock.ts uses). Well maybe it can, but it gets the wrong version of React, in any case, due to Next shenanigans. I'm not sure.

But maybe there is still some way for the middleware to

(A) do all the mocking setup (even delaying the request to run loaders)?

(B) somehow pass an id through to the request so the mocking library can read it from the cache.

src/mock.ts Outdated
Comment on lines 24 to 25
// Important -- we need to do this because otherwise the page renders *before* the layout
await new Promise((r) => setTimeout(r, 0));
Copy link
Member Author

Choose a reason for hiding this comment

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

Note this bit. Another issue with using the layout to setup the mocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant