-
Notifications
You must be signed in to change notification settings - Fork 179
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
Storybook: Fix Circular Dependencies and fast refresh #11161
Conversation
.storybook/preview.js
Outdated
import { | ||
GlobalStyle, | ||
EditorConfigProvider, | ||
} from '@googleforcreators/story-editor'; |
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.
The problem continues - fast refresh does not work if this import exists.
Have fixed circular dependencies in all packages, but maybe there are circular dependencies still from this file? Not sure atm, but will keep digging.
They don't show up in the webpack circular dependency plugin, so wondering if it's due to something different.
04f1c8d
to
ce0d39e
Compare
Dep Graph: packages/story-editor/src/app/highlights/index.js packages/story-editor/src/app/highlights/provider.js packages/story-editor/src/app/highlights/states.js packages/story-editor/src/components/library/constants.js // cut off here packages/story-editor/src/components/library/panes/media/local/index.js packages/story-editor/src/components/library/panes/media/local/mediaPane.js packages/story-editor/src/components/library/panes/media/common/paginatedMediaGallery.js packages/story-editor/src/components/library/panes/media/common/mediaGallery.js packages/story-editor/src/components/library/panes/media/common/mediaElement.js packages/story-editor/src/components/library/panes/media/common/innerElement.js packages/story-editor/src/components/library/panes/shared/libraryMoveable.js packages/story-editor/src/components/canvas/index.js packages/story-editor/src/components/canvas/canvas.js packages/story-editor/src/components/canvas/canvasLayout.js packages/story-editor/src/components/floatingMenu/index.js packages/story-editor/src/components/floatingMenu/layer.js packages/story-editor/src/components/floatingMenu/menu.js packages/story-editor/src/components/floatingMenu/menus/index.js packages/story-editor/src/components/floatingMenu/menus/selector.js packages/story-editor/src/components/floatingMenu/menus/image.js packages/story-editor/src/components/floatingMenu/elements/index.js packages/story-editor/src/components/floatingMenu/elements/more.js packages/story-editor/src/app/highlights/index.js
* looks like there's still a circular dep when diving from preview.js into the editor??
2bc27c8
to
9a3118d
Compare
// Disable reason: | ||
// Importing from the dashboard and story editor roots break fast refresh in storybook. | ||
// Prevented by importing the necessary providers and configs directly. | ||
/* eslint-disable import/no-relative-packages */ | ||
import { GlobalStyle as DashboardGlobalStyle } from '../packages/dashboard/src/theme'; | ||
import DashboardKeyboardOnlyOutline from '../packages/dashboard/src/utils/keyboardOnlyOutline'; | ||
import DashboardConfigProvider from '../packages/dashboard/src/app/config/configProvider'; | ||
import ApiProvider from '../packages/dashboard/src/app/api/apiProvider'; | ||
import EditorConfigProvider from '../packages/story-editor/src/app/config/configProvider'; | ||
/* eslint-enable import/no-relative-packages */ | ||
|
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.
The story editor and dashboard stories were not fast refreshing, and were logging warnings like this:
Dashboard | Story Editor |
---|---|
Importing directly from the modules here removes these warnings and fixes fast refresh.
Got the idea from this thread
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.
Interesting 🤔
I guess storybook doesn't like npm workspaces where the packages are referenced from node_modules
but actually symlinked.
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.
Maybe 🤷 but seems like finding these imports using relative paths seems to fix it. Luckily this change can be scoped to this one file.
export const PANE_IDS = { | ||
MEDIA: 'media', | ||
MEDIA_3P: 'media3p', | ||
TEXT: 'text', | ||
SHAPES: 'shapes', | ||
ELEMENTS: 'elements', | ||
PAGE_TEMPLATES: 'pageTemplates', | ||
}; |
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.
This is a weird diff. Two things happened here:
- Broke a loop that involved the checklist cards and the thumbnail wrapper + video checklist cards: 566a1b3 and 083b38b. The file in red was deleted.
- Broke a loop that involved the highlights provider: c5dd4c6. The file in green was added and these imports were updated
These two are not related.
Size Change: -4.12 kB (0%) Total Size: 2.59 MB
ℹ️ View Unchanged
|
Plugin builds for 5f1c855 are ready 🛎️!
|
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.
Wow, great job deducing what was causing this. Thanks for the explanation. Tested locally and fast refresh for storybook is back. Not seeing any errors there and app works as expected locally as well.
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.
Indeed, kudos for going down this rabbit hole!
The bundle size improvement is also a nice side effect
d8335ac
to
5f1c855
Compare
Context
After #6304, storybook fast refresh stopped working. Saw some strange warnings, but ultimately think that it's due to circular dependencies.
This PR is a try at fixing those
This issue on github looks similar to our problem
Summary
2. Fixes these circular dependencies found in `/packages`:
Relevant Technical Choices
Adding webpack's
CircularDependencyPlugin
. Should help to track future circular deps.To-do
User-facing changes
n/a
Testing Instructions
This PR can be tested by following these steps:
Ignored an update to an unaccepted module
Ignored an update to an unaccepted module
Ignored an update to an unaccepted module
Reviews
Does this PR have a security-related impact?
no
Does this PR change what data or activity we track or use?
no
Does this PR have a legal-related impact?
no
Checklist
Type: XYZ
label to the PRFixes #10788