-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[WIP] (#1736) ability to force re-render a story #2463
[WIP] (#1736) ability to force re-render a story #2463
Conversation
Also adds support for redux DevTools in react/client
Codecov Report
@@ Coverage Diff @@
## master #2463 +/- ##
==========================================
- Coverage 32.64% 32.61% -0.03%
==========================================
Files 397 397
Lines 8847 8855 +8
Branches 951 959 +8
==========================================
Hits 2888 2888
+ Misses 5292 5289 -3
- Partials 667 678 +11
Continue to review full report at Codecov.
|
Think we should port this over for vue and angular as well if this was to be added as a feature. |
@danielduan Will do. I'll port it to Vue and Angular when I get a chance, then I'll update the docs for all of them |
@@ -53,3 +59,5 @@ const renderUI = () => { | |||
}; | |||
|
|||
reduxStore.subscribe(renderUI); | |||
|
|||
export const forceReRender = () => renderUI(); |
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.
If the story didn't change, why would this work?
Should return true, and the story won't be re-rendered?
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.
Never mind, I mis-interpreted the code.
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.
I was just looking at that code, funnily enough and I think it's a bit broken, I was going to send a PR to fix it.
The current (psuedo) logic is:
render() {
// line linked above
if (storyDifferent) {
ReactDOM.unmountComponentAtNode(rootEl);
}
// later
ReactDOM.render(element, rootEl);
}
So it always calls render
and sometimes calls unmount
. This actually breaks the React lifecycle in weird ways.
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.
So, if I was to fix the above (probably changing it to: if (!storyDifferent) return;
, this PR would no longer work.
We should consider if we want to support this forceRerender
functionality? I suppose we do? If so we will need a more declarative way to make it work, I don't think we should retain the above bug just to make it work.
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.
Probably the easiest way would be to add a "key" to the redux store that is changed when you call forceRerender
and to also check if the key has changed.
window.__REDUX_DEVTOOLS_EXTENSION__ && | ||
window.__REDUX_DEVTOOLS_EXTENSION__({ name: 'Storybook Preview', instanceId: 'sbPreview' }) | ||
); | ||
/* eslint-enable */ |
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.
What's happening with this change? It seems unrelated.
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.
Correct, it is unrelated. It's enabling dev tools. Do you think it should be in a separate branch/pr.
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.
I think yeah, let's move to a separate PR
@@ -53,3 +59,5 @@ const renderUI = () => { | |||
}; | |||
|
|||
reduxStore.subscribe(renderUI); | |||
|
|||
export const forceReRender = () => renderUI(); |
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.
I was just looking at that code, funnily enough and I think it's a bit broken, I was going to send a PR to fix it.
The current (psuedo) logic is:
render() {
// line linked above
if (storyDifferent) {
ReactDOM.unmountComponentAtNode(rootEl);
}
// later
ReactDOM.render(element, rootEl);
}
So it always calls render
and sometimes calls unmount
. This actually breaks the React lifecycle in weird ways.
@@ -53,3 +59,5 @@ const renderUI = () => { | |||
}; | |||
|
|||
reduxStore.subscribe(renderUI); | |||
|
|||
export const forceReRender = () => renderUI(); |
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.
So, if I was to fix the above (probably changing it to: if (!storyDifferent) return;
, this PR would no longer work.
We should consider if we want to support this forceRerender
functionality? I suppose we do? If so we will need a more declarative way to make it work, I don't think we should retain the above bug just to make it work.
@dangreenisrael I am making some of these changes on another branch (because I need the lifecycle to work properly) so LMK if it makes sense to port them across here. |
PS as an aside -- is it expected that all new functionality needs to be implemented in all 3 (should it be 4, what about RN?) view layers to be shipped? For instance, I personally wouldn't have much idea how to (at least idiomatically) implement this in Vue and Angular. It seems like quite a barrier (maybe that's a good thing). |
@tmeasday I'm planning to do a deep dive into force re-render over the winter holidays (probably December 27,28,29. Do you think your PR will be merged by then. |
@tmeasday @ndelangen Do you guys want to set up a time to chat about force re-render so we can all get on the same page |
I'm pretty convinced we should merge the above. However, I think it shouldn't be too hard to amend the above to consider a |
@tmeasday, I'll rebase off 3.3/your branch before getting back to work on this |
Please check if this still works after @tmeasday's change.. |
Changes look good to me. |
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.
LGTM, let's get rid of the devtools
window.__REDUX_DEVTOOLS_EXTENSION__ && | ||
window.__REDUX_DEVTOOLS_EXTENSION__({ name: 'Storybook Preview', instanceId: 'sbPreview' }) | ||
); | ||
/* eslint-enable */ |
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.
I think yeah, let's move to a separate PR
I addressed the concerns, but his is unable to look at it right now.
Merging as @tmeasday's requested changes were made |
Thank you guys for the great work. As far as I can see this has been merged in and master. I'm using version 3.3.12 but cannot run the example code. @dangreenisrael: Sadly when using the example code I run into the following error
It is thrown two times: When I look into the cra-kitchensink folder I don't see anything special in the setup which differs from mine. Is there still a change this is related to setup? For example that I'm using different loaders? (TS, SCSS) Thanks in advance! |
@stefanKuijers could you open up an issue for this? Also, can you reproduce this issue in a public repo? |
@stefanKuijers This feature was merged after |
Thanks for the reply guys. I saw a few times in the branch names a 3.3 which is why I thought it was still part of 3.3. Thanks for the great work! I will wait until 3.4.0. I see on the side now that this is assigned to the 3.4 milestone. |
Issue: #1736
What I did
added
forceReRender
to the exports in'@storybook/react'
How to test
Storyshots
Does this need a new example in the kitchen sink apps?
Yes
Does this need an update to the documentation?
Yes
Acceptance criteria:
Platforms
Functionality
Misc
Sceenshot
Future possibility
Standard event that can be emitted to force a reload