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

Addons: Change our internal addons to be functions Yann #30242

Closed
Tracked by #30166
kasperpeulen opened this issue Jan 10, 2025 · 0 comments
Closed
Tracked by #30166

Addons: Change our internal addons to be functions Yann #30242

kasperpeulen opened this issue Jan 10, 2025 · 0 comments
Assignees

Comments

@kasperpeulen
Copy link
Contributor

kasperpeulen commented Jan 10, 2025

Make sure preview export a default function:

const preview = {
    parameters: {},
}

const fn = () => preview;
Object.assign(fn, preview);
export default fn;

And adjust the preview annotation loading to call this function for CSF3 stories:

const getProjectAnnotations = () => {
const previewAnnotations = ['{{previewAnnotations_requires}}'];
// the last one in this array is the user preview
const preview = previewAnnotations[previewAnnotations.length - 1];
const csfFactoryPreview = Object.values(preview).find((module) => {
return 'isCSFFactoryPreview' in module;
});
if (csfFactoryPreview) {
return csfFactoryPreview.annotations;
}
return composeConfigs(previewAnnotations);
};

const getPreviewAnnotationsFunction = `
const getProjectAnnotations = async (hmrPreviewAnnotationModules = []) => {
const preview = await import('${previewFileUrl}');
const csfFactoryPreview = Object.values(preview).find(module => {
return 'isCSFFactoryPreview' in module
});
if (csfFactoryPreview) {
return csfFactoryPreview.annotations;
}

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

No branches or pull requests

2 participants