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

refactor createUseStyles to work with react-hot-loader #1237

Merged
merged 1 commit into from
Dec 28, 2019

Conversation

bs85
Copy link
Contributor

@bs85 bs85 commented Nov 28, 2019

isFirstRender is broken when using react-hot-loader, as it unmounts and remounts the components, but preserves hook state all the way through, including isFirstRender.

The removeDynamicRules hook runs first, and an error is thrown once updateDynamicRules runs as the rules have been removed.

With those changes everything should run in the proper order.

@bs85 bs85 requested a review from HenriBeck as a code owner November 28, 2019 15:40
@kof
Copy link
Member

kof commented Nov 28, 2019

Tests are passing, ignore the CI, it's a permissions probl. Looks good at the first glance. Need to check if we have all tests for cases like

  1. 2 elements of the same component reusing the same style sheet if there are no dynamic rules
  2. 2 elements are reusing the same static sheet and dynamic rules are created and updatable
  3. when 1 of 2 elements unmounts - static sheet that is in use by the other element is still there, dynamic rules used only by that unmounted element are removed.

@kof kof self-requested a review November 28, 2019 16:01
@kof
Copy link
Member

kof commented Nov 28, 2019

@HenriBeck @eps1lon do you see any problems with this approach?

@kof kof mentioned this pull request Dec 4, 2019
3 tasks
@kof
Copy link
Member

kof commented Dec 14, 2019

@HenriBeck do you see anything wrong with this PR? I would merge it tomorrow otherwise.

})

useEffectOrLayoutEffect(
const [sheet, dynamicRules] = React.useMemo(
Copy link
Member

Choose a reason for hiding this comment

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

If I remember correctly there was a problem with using React.useMemo as it can be rerun by React at a given point of time.

I think @eps1lon knew more about this.

Copy link
Member

Choose a reason for hiding this comment

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

I think you are talking about the theoretical situation in async mode, not sure if it was made real.

if (state.sheet && state.dynamicRules && !isFirstMount.current) {
updateDynamicRules(data, state.sheet, state.dynamicRules)
if (sheet && dynamicRules && !isFirstMount.current) {
updateDynamicRules(data, sheet, dynamicRules)
}
},
[data]
)

useEffectOrLayoutEffect(
Copy link
Member

Choose a reason for hiding this comment

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

Can't we just move this above the updateDynamicRules hook?

Copy link
Member

Choose a reason for hiding this comment

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

That cleanup depends on the sheet argument, the one above on data.

Copy link
Member

Choose a reason for hiding this comment

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

Seems correct to me

@kof kof merged commit 9f7924e into cssinjs:master Dec 28, 2019
@kof
Copy link
Member

kof commented Dec 28, 2019

@bs85 going to release it together with one more important bugfix that I have been working on lately

@bs85
Copy link
Contributor Author

bs85 commented Dec 28, 2019

Great, thank you!

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.

3 participants