Skip to content

Conversation

@mayagbarnes
Copy link
Collaborator

@mayagbarnes mayagbarnes commented Oct 16, 2025

Describe your changes

Part 1 of StreamlitContextProvider updates

  • Moves the pull of formsData from Block.tsx
  • Updates renderWithContext function to return a rerenderWithContexts function to allow for changes in context values on rerender for more testing flexibility

Removes addScriptFinishedHandler & removeScriptFinishedHandler from context as these are used one level down in AppView component.

Testing Plan

  • JS Unit Tests: ✅ Updated

@snyk-io
Copy link
Contributor

snyk-io bot commented Oct 16, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12788/streamlit-1.51.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-12788.streamlit.app (☁️ Deploy here if not accessible)

Copy link
Collaborator Author

mayagbarnes commented Oct 16, 2025

@mayagbarnes mayagbarnes changed the title Update formsContext pull to Form Update FormsContext Oct 16, 2025
@mayagbarnes mayagbarnes changed the title Update FormsContext Update FormsContext Oct 16, 2025
@mayagbarnes mayagbarnes added security-assessment-completed Security assessment has been completed for PR change:refactor PR contains code refactoring without behavior change impact:users PR changes affect end users labels Oct 16, 2025
@sfc-gh-mbarnes sfc-gh-mbarnes force-pushed the forms-context-fix branch 4 times, most recently from bd2f963 to 8f45c0a Compare October 21, 2025 21:25
@mayagbarnes mayagbarnes marked this pull request as ready for review October 27, 2025 16:47
@mayagbarnes mayagbarnes requested a review from Copilot October 27, 2025 16:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR moves the consumption of formsData from Block.tsx down to the Form component, improving rendering performance by ensuring only Form components re-render when form data changes. It also removes addScriptFinishedHandler and removeScriptFinishedHandler from LibContext since these are only used in AppView. Additionally, the renderWithContexts test utility is enhanced to support updating context values during re-renders.

Key Changes:

  • Moved formsData consumption from Block.tsx to Form.tsx for better performance
  • Removed script finished handler methods from LibContext
  • Enhanced renderWithContexts to return a rerenderWithContexts function for more flexible testing

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
frontend/lib/src/test_util.tsx Added RenderWithContextsResult interface and rerenderWithContexts function to support context updates during re-renders
frontend/lib/src/components/widgets/Form/Form.tsx Moved formsData and scriptRunState consumption into Form component, removing props dependencies
frontend/lib/src/components/widgets/Form/Form.test.tsx Updated tests to use new context-based approach with rerenderWithContexts
frontend/lib/src/hooks/useWidgetManagerElementState.test.tsx Updated test to use renderWithContexts and provide formsData via context
frontend/lib/src/components/core/Block/Block.tsx Removed formsData consumption and form-related prop calculations
frontend/lib/src/components/core/LibContext.tsx Removed addScriptFinishedHandler and removeScriptFinishedHandler from context interface
frontend/lib/src/components/core/FormsContext.tsx Updated documentation comments and fixed typo
frontend/app/src/components/StreamlitContextProvider.tsx Removed script finished handler props from provider
frontend/app/src/components/AppView/AppView.tsx Added script finished handlers as direct props instead of from context
frontend/app/src/components/AppView/AppView.test.tsx Added mock handlers to test props
frontend/app/src/App.tsx Moved script finished handlers from context to AppView props

@sfc-gh-mbarnes sfc-gh-mbarnes force-pushed the forms-context-fix branch 2 times, most recently from 5c4a28d to 91407b6 Compare October 28, 2025 07:39
Copy link
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco left a comment

Choose a reason for hiding this comment

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

Looks like there's a merge conflict with Block, but should be good to go afterwards!

@mayagbarnes mayagbarnes merged commit 01e5b61 into develop Oct 30, 2025
37 of 38 checks passed
@mayagbarnes mayagbarnes deleted the forms-context-fix branch October 30, 2025 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:refactor PR contains code refactoring without behavior change impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants