Skip to content

Conversation

@nishasy
Copy link
Contributor

@nishasy nishasy commented Nov 4, 2025

Summary:

APIOptions is passed around everywhere, even in components it's not directly used
but is just passed down to children who use it.

It would clean up the code to put APIOptions in a context.

In this PR:

  • Create the APIOptions context
  • Use it within EditorPage and its children
  • Use it within ArticleEditor

I'll have a different PR to add the context on the renderer side.

Issue: none

Test plan:

pnpm jest

Storybook
/?path=/story/editors-editorpage--demo
/?path=/story/editors-articleeditor--demo

@nishasy nishasy self-assigned this Nov 4, 2025
issues?: Issue[];
};

const IssuesPanel = ({apiOptions, issues = []}: IssuesPanelProps) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I really like that we won't need to drill this APIOptions all over. Using a hook (or for our old class components, an HOC) will really clean things up and focus where we use APIOptions.

return [
<div className="perseus-editor-row" key={i}>
<fieldset disabled={editingDisabled}>
<APIOptionsContext.Provider
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, this is what I was thinking. Components that are exported from @khanacademy/perseus-editor accept APIOptions as a prop, but then set up a context to provide it down the component tree. 👍

I think this gives us safety through TypeScript prop types, but relieves us from prop-drilling everywhere.

}

getApiOptions(): APIOptionsWithDefaults {
getDeviceBasedApiOptions(): APIOptionsWithDefaults {
Copy link
Collaborator

Choose a reason for hiding this comment

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

💯

</div>
<APIOptionsContext.Consumer>
{({apiOptions}) => {
this.contextApiOptions = apiOptions;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Putting this in a field feels a bit risky for me but I can't quite express why. I think ideally we'd pass the apiOptions down to render functions, or better yet, we'd extract sub-components from this big Editor so they can just use the APIOptionsContext when they need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it feels weird. I'll look into some other approaches.

@nishasy nishasy marked this pull request as ready for review November 5, 2025 23:17
@nishasy nishasy requested review from a team and handeyeco November 5, 2025 23:17
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

🗄️ Schema Change: No Changes ✅

@github-actions github-actions bot added item-splitting-change schema-change Attached to PRs when we detect Perseus Schema changes in it and removed schema-change Attached to PRs when we detect Perseus Schema changes in it item-splitting-change labels Nov 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

🛠️ Item Splitting: No Changes ✅

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Size Change: +140 B (+0.03%)

Total Size: 498 kB

Filename Size Change
packages/perseus-editor/dist/es/index.js 97.2 kB +42 B (+0.04%)
packages/perseus/dist/es/index.js 204 kB +98 B (+0.05%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.8 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 5.98 kB
packages/math-input/dist/es/index.js 99.2 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.item-splitting.js 13.1 kB
packages/perseus-core/dist/es/index.js 22.4 kB
packages/perseus-linter/dist/es/index.js 7.21 kB
packages/perseus-score/dist/es/index.js 9.2 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/strings.js 7.73 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (439a016) and published it to npm. You
can install it using the tag PR3013.

Example:

pnpm add @khanacademy/perseus@PR3013

If you are working in Khan Academy's frontend, you can run the below command.

./dev/tools/bump_perseus_version.ts -t PR3013

If you are working in Khan Academy's webapp, you can run the below command.

./dev/tools/bump_perseus_version.js -t PR3013

@nishasy nishasy marked this pull request as draft November 6, 2025 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants