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

[wb1812.0.fixrenderstate] Make sure RenderState.Root is an internal concept only #2387

Merged
merged 3 commits into from
Dec 11, 2024

Conversation

somewhatabstract
Copy link
Member

@somewhatabstract somewhatabstract commented Dec 11, 2024

Summary:

This addresses an issue where useRenderState would return RenderState.Root during initial render to components nested inside our RenderStateRoot component, when they should only ever see Initial or Standard.

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 and InitialFallback components, code doesn't need to know if it's the root render or not. It's an easier API if they just always see Initial or Standard. 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 with useId.

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 the useRenderState hook. In real terms, consumers should be unaffected, but changing exports like this should be a major release so following protocol.

@somewhatabstract somewhatabstract self-assigned this Dec 11, 2024
@somewhatabstract somewhatabstract requested review from nedredmond and a team December 11, 2024 18:02
Copy link

changeset-bot bot commented Dec 11, 2024

🦋 Changeset detected

Latest commit: 00b2edd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@khanacademy/wonder-blocks-core Major
@khanacademy/wonder-blocks-accordion Patch
@khanacademy/wonder-blocks-banner Patch
@khanacademy/wonder-blocks-birthday-picker Patch
@khanacademy/wonder-blocks-breadcrumbs Patch
@khanacademy/wonder-blocks-button Patch
@khanacademy/wonder-blocks-cell Patch
@khanacademy/wonder-blocks-clickable Patch
@khanacademy/wonder-blocks-data Patch
@khanacademy/wonder-blocks-dropdown Patch
@khanacademy/wonder-blocks-form Patch
@khanacademy/wonder-blocks-grid Patch
@khanacademy/wonder-blocks-icon-button Patch
@khanacademy/wonder-blocks-icon Patch
@khanacademy/wonder-blocks-labeled-field Patch
@khanacademy/wonder-blocks-layout Patch
@khanacademy/wonder-blocks-link Patch
@khanacademy/wonder-blocks-modal Patch
@khanacademy/wonder-blocks-pill Patch
@khanacademy/wonder-blocks-popover Patch
@khanacademy/wonder-blocks-progress-spinner Patch
@khanacademy/wonder-blocks-search-field Patch
@khanacademy/wonder-blocks-switch Patch
@khanacademy/wonder-blocks-testing Patch
@khanacademy/wonder-blocks-toolbar Patch
@khanacademy/wonder-blocks-tooltip Patch
@khanacademy/wonder-blocks-typography Patch

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

@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .changeset/bright-apes-sparkle.md, __docs__/wonder-blocks-core/exports.use-render-state.mdx, packages/wonder-blocks-core/src/components/initial-fallback.tsx, packages/wonder-blocks-core/src/components/render-state-context.ts, packages/wonder-blocks-core/src/components/render-state-root.tsx, packages/wonder-blocks-core/src/hooks/use-render-state.ts, packages/wonder-blocks-core/src/hooks/use-unique-id.ts, packages/wonder-blocks-core/src/hooks/__tests__/use-unique-id.test.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Contributor

github-actions bot commented Dec 11, 2024

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

Copy link
Contributor

github-actions bot commented Dec 11, 2024

Size Change: +33 B (+0.03%)

Total Size: 102 kB

Filename Size Change
packages/wonder-blocks-core/dist/es/index.js 3.48 kB +33 B (+0.96%)
ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 3.78 kB
packages/wonder-blocks-banner/dist/es/index.js 1.53 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.77 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 887 B
packages/wonder-blocks-button/dist/es/index.js 4.04 kB
packages/wonder-blocks-cell/dist/es/index.js 2.01 kB
packages/wonder-blocks-clickable/dist/es/index.js 3.06 kB
packages/wonder-blocks-data/dist/es/index.js 6.24 kB
packages/wonder-blocks-dropdown/dist/es/index.js 19.2 kB
packages/wonder-blocks-form/dist/es/index.js 6.28 kB
packages/wonder-blocks-grid/dist/es/index.js 1.36 kB
packages/wonder-blocks-i18n/dist/es/index.js 4.77 kB
packages/wonder-blocks-icon-button/dist/es/index.js 2.95 kB
packages/wonder-blocks-icon/dist/es/index.js 871 B
packages/wonder-blocks-labeled-field/dist/es/index.js 72 B
packages/wonder-blocks-layout/dist/es/index.js 1.82 kB
packages/wonder-blocks-link/dist/es/index.js 2.28 kB
packages/wonder-blocks-modal/dist/es/index.js 5.43 kB
packages/wonder-blocks-pill/dist/es/index.js 1.65 kB
packages/wonder-blocks-popover/dist/es/index.js 4.87 kB
packages/wonder-blocks-progress-spinner/dist/es/index.js 1.52 kB
packages/wonder-blocks-search-field/dist/es/index.js 1.38 kB
packages/wonder-blocks-switch/dist/es/index.js 1.94 kB
packages/wonder-blocks-testing-core/dist/es/index.js 3.74 kB
packages/wonder-blocks-testing/dist/es/index.js 1.07 kB
packages/wonder-blocks-theming/dist/es/index.js 693 B
packages/wonder-blocks-timing/dist/es/index.js 1.8 kB
packages/wonder-blocks-tokens/dist/es/index.js 2.36 kB
packages/wonder-blocks-toolbar/dist/es/index.js 905 B
packages/wonder-blocks-tooltip/dist/es/index.js 7.08 kB
packages/wonder-blocks-typography/dist/es/index.js 1.23 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Dec 11, 2024

A new build was pushed to Chromatic! 🚀

https://5e1bf4b385e3fb0020b7073c-apnduxhdvs.chromatic.com/

Chromatic results:

Metric Total
Captured snapshots 377
Tests with visual changes 0
Total stories 517
Inherited (not captured) snapshots [TurboSnap] 0
Tests on the build 377

Copy link
Member

@jandrade jandrade left a 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 🚢

Comment on lines -53 to -58
if (renderState === RenderState.Root) {
throw new Error(
"Components using useUniqueIdWithoutMock() should be descendants of <RenderStateRoot>",
);
}

Copy link
Member

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!!

@somewhatabstract somewhatabstract merged commit f4abd57 into main Dec 11, 2024
14 checks passed
@somewhatabstract somewhatabstract deleted the wb1812.0.fixrenderstate branch December 11, 2024 23:17
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (0955be7) to head (00b2edd).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@     Coverage Diff      @@
##   main   #2387   +/-   ##
============================
============================

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0955be7...00b2edd. Read the comment docs.

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