-
Notifications
You must be signed in to change notification settings - Fork 10
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
[wb1812.0.fixrenderstate] Make sure RenderState.Root is an internal concept only #2387
Conversation
🦋 Changeset detectedLatest commit: 00b2edd The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
npm Snapshot: Published🎉 Good news!! We've packaged up the latest commit from this PR (e3eec76) and published all packages with changesets to npm. You can install the packages in webapp by running: ./services/static/dev/tools/deploy_wonder_blocks.js --tag="PR2387" Packages can also be installed manually by running: yarn add @khanacademy/wonder-blocks-<package-name>@PR2387 |
Size Change: +33 B (+0.03%) Total Size: 102 kB
ℹ️ View Unchanged
|
A new build was pushed to Chromatic! 🚀https://5e1bf4b385e3fb0020b7073c-apnduxhdvs.chromatic.com/ Chromatic results:
|
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 looks great! thanks for simplifying the public API 🚢
packages/wonder-blocks-core/src/components/render-state-context.ts
Outdated
Show resolved
Hide resolved
if (renderState === RenderState.Root) { | ||
throw new Error( | ||
"Components using useUniqueIdWithoutMock() should be descendants of <RenderStateRoot>", | ||
); | ||
} | ||
|
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.
praise: It is great seeing how this got simplified!!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2387 +/- ##
============================
============================
Continue to review full report in Codecov by Sentry.
|
Summary:
This addresses an issue where
useRenderState
would returnRenderState.Root
during initial render to components nested inside ourRenderStateRoot
component, when they should only ever seeInitial
orStandard
.I suspect this was happening due to hook execution order and render order. React component render functions are executed from the inside out, and I suspect that because of this, the initial call to
useRenderState
is using the default context value, because the root component hasn't rendered it's value yet - a general flaw in hook-based context access.However, for everything but
RenderStateRoot
andInitialFallback
components, code doesn't need to know if it's the root render or not. It's an easier API if they just always seeInitial
orStandard
. This change makes that happen. The only components that need to know are those that need to render the actual context, and our consumers don't need to do that.This addresses an issue where the
useUniqueId
hook and it's initial render fallback version would throw an error on initial render. It's a precursor PR to unblock folks while we work on replacing our unique ID stuff withuseId
.Issue: WB-1812
Test plan:
yarn test
yarn typecheck
I also checked our Wonder Blocks consumers to verify that they don't care about the "root" render state (as they shouldn't).
Release Info:
This is a major release of Core because we are changing the
RenderState
enum to remove a value, and changing the behavior of theuseRenderState
hook. In real terms, consumers should be unaffected, but changing exports like this should be a major release so following protocol.