Skip to content

[feat] Add the BidiComponentContextProvider implementation#12754

Merged
sfc-gh-bnisco merged 1 commit intodevelopfrom
bnisco/ccv2-stack-30
Oct 24, 2025
Merged

[feat] Add the BidiComponentContextProvider implementation#12754
sfc-gh-bnisco merged 1 commit intodevelopfrom
bnisco/ccv2-stack-30

Conversation

@sfc-gh-bnisco
Copy link
Copy Markdown
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco commented Oct 10, 2025

Describe your changes

Added a new BidiComponentContextProvider component and utility functions for parsing data. The provider creates a context with all necessary data and functions for CCv2 instances, including:

  • Component metadata (name, ID, form ID)
  • Content (HTML, CSS, JS)
  • Data parsing from various formats (JSON, Arrow, bytes, mixed)
  • Widget state management
  • Theme information

Also implemented a comprehensive data parser with tests that handles different data types:

  • JSON data
  • Arrow data
  • Raw bytes
  • Mixed data (combining JSON with Arrow blobs)

GitHub Issue Link (if applicable)

Testing Plan

  • Unit Tests: Added comprehensive tests for the parseBidiComponentData utility, covering all data types and edge cases
  • The context provider is a pure component that passes data through, so will be tested by later PRs

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Oct 10, 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
Copy Markdown
Contributor

github-actions bot commented Oct 10, 2025

✅ PR preview is ready!

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

Copy link
Copy Markdown
Collaborator Author

sfc-gh-bnisco commented Oct 10, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sfc-gh-bnisco sfc-gh-bnisco force-pushed the bnisco/ccv2-stack-30 branch 2 times, most recently from d1b0bbb to f9159b0 Compare October 24, 2025 19:07
@sfc-gh-bnisco sfc-gh-bnisco force-pushed the bnisco/ccv2-stack-29 branch 2 times, most recently from 3fb6bd8 to c5f3b2f Compare October 24, 2025 19:10
@sfc-gh-bnisco sfc-gh-bnisco force-pushed the bnisco/ccv2-stack-30 branch 2 times, most recently from fdc0e6e to 85d8403 Compare October 24, 2025 19:57
@sfc-gh-bnisco sfc-gh-bnisco force-pushed the bnisco/ccv2-stack-29 branch 2 times, most recently from 4fd4900 to 28e0810 Compare October 24, 2025 19:59
@sfc-gh-bnisco sfc-gh-bnisco force-pushed the bnisco/ccv2-stack-30 branch 2 times, most recently from 43e1228 to f9cec43 Compare October 24, 2025 22:04
@sfc-gh-bnisco sfc-gh-bnisco force-pushed the bnisco/ccv2-stack-29 branch 3 times, most recently from c81bc3d to f22703a Compare October 24, 2025 22:33
Copy link
Copy Markdown
Collaborator Author

sfc-gh-bnisco commented Oct 24, 2025

Merge activity

  • Oct 24, 11:01 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Oct 24, 11:03 PM UTC: Graphite rebased this pull request as part of a merge.
  • Oct 24, 11:27 PM UTC: @sfc-gh-bnisco merged this pull request with Graphite.

@sfc-gh-bnisco sfc-gh-bnisco changed the base branch from bnisco/ccv2-stack-29 to graphite-base/12754 October 24, 2025 23:01
@sfc-gh-bnisco sfc-gh-bnisco changed the base branch from graphite-base/12754 to develop October 24, 2025 23:01
return bytes ?? null
case "mixed": {
if (mixedJson && arrowBlobs) {
if (mixedJson) {

Check warning

Code scanning / CodeQL

Useless conditional Warning

This use of variable 'mixedJson' always evaluates to true.

Copilot Autofix

AI 5 months ago

The fix is straightforward: remove the useless conditional if (mixedJson) { ... } at line 59 and move its contents one level up, so that the block is only executed when the outer conditional (if (mixedJson && arrowBlobs)) is true. Specifically, replace lines 58–72 so that the parsing of mixedJson, construction of arrowBlobsMap, and call to reconstructMixedData occur directly within the block guarded by the outer conditional. No imports, method definitions, or additional variable definitions are needed.

Suggested changeset 1
frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts b/frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts
--- a/frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts
+++ b/frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts
@@ -56,20 +56,16 @@
       return bytes ?? null
     case "mixed": {
       if (mixedJson && arrowBlobs) {
-        if (mixedJson) {
-          const jsonData = JSON.parse(mixedJson)
+        const jsonData = JSON.parse(mixedJson)
 
-          const arrowBlobsMap: Record<string, Uint8Array> = {}
-          if (arrowBlobs) {
-            Object.entries(arrowBlobs).forEach(([key, arrowProto]) => {
-              if (arrowProto?.data) {
-                arrowBlobsMap[key] = arrowProto.data
-              }
-            })
+        const arrowBlobsMap: Record<string, Uint8Array> = {}
+        Object.entries(arrowBlobs).forEach(([key, arrowProto]) => {
+          if (arrowProto?.data) {
+            arrowBlobsMap[key] = arrowProto.data
           }
+        })
 
-          return reconstructMixedData(jsonData, arrowBlobsMap)
-        }
+        return reconstructMixedData(jsonData, arrowBlobsMap)
       }
       return null
     }
EOF
@@ -56,20 +56,16 @@
return bytes ?? null
case "mixed": {
if (mixedJson && arrowBlobs) {
if (mixedJson) {
const jsonData = JSON.parse(mixedJson)
const jsonData = JSON.parse(mixedJson)

const arrowBlobsMap: Record<string, Uint8Array> = {}
if (arrowBlobs) {
Object.entries(arrowBlobs).forEach(([key, arrowProto]) => {
if (arrowProto?.data) {
arrowBlobsMap[key] = arrowProto.data
}
})
const arrowBlobsMap: Record<string, Uint8Array> = {}
Object.entries(arrowBlobs).forEach(([key, arrowProto]) => {
if (arrowProto?.data) {
arrowBlobsMap[key] = arrowProto.data
}
})

return reconstructMixedData(jsonData, arrowBlobsMap)
}
return reconstructMixedData(jsonData, arrowBlobsMap)
}
return null
}
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
const jsonData = JSON.parse(mixedJson)

const arrowBlobsMap: Record<string, Uint8Array> = {}
if (arrowBlobs) {

Check warning

Code scanning / CodeQL

Useless conditional Warning

This use of variable 'arrowBlobs' always evaluates to true.

Copilot Autofix

AI 5 months ago

To fix the problem, simply remove the conditional if (arrowBlobs) (lines 63-69). The forEach logic that populates arrowBlobsMap can be safely executed after the existing outer check (if (mixedJson && arrowBlobs)), as arrowBlobs is guaranteed to be non-null at that point. This will clean up the code without changing its behavior.

Specifically:

  • In frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts, lines 63-69 can be replaced by just the forEach loop (without the wrapping conditional) since arrowBlobs is already verified.
  • No other imports or definitions are needed.

Suggested changeset 1
frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts b/frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts
--- a/frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts
+++ b/frontend/lib/src/components/widgets/BidiComponent/utils/parseBidiComponentData.ts
@@ -60,13 +60,11 @@
           const jsonData = JSON.parse(mixedJson)
 
           const arrowBlobsMap: Record<string, Uint8Array> = {}
-          if (arrowBlobs) {
-            Object.entries(arrowBlobs).forEach(([key, arrowProto]) => {
-              if (arrowProto?.data) {
-                arrowBlobsMap[key] = arrowProto.data
-              }
-            })
-          }
+          Object.entries(arrowBlobs).forEach(([key, arrowProto]) => {
+            if (arrowProto?.data) {
+              arrowBlobsMap[key] = arrowProto.data
+            }
+          })
 
           return reconstructMixedData(jsonData, arrowBlobsMap)
         }
EOF
@@ -60,13 +60,11 @@
const jsonData = JSON.parse(mixedJson)

const arrowBlobsMap: Record<string, Uint8Array> = {}
if (arrowBlobs) {
Object.entries(arrowBlobs).forEach(([key, arrowProto]) => {
if (arrowProto?.data) {
arrowBlobsMap[key] = arrowProto.data
}
})
}
Object.entries(arrowBlobs).forEach(([key, arrowProto]) => {
if (arrowProto?.data) {
arrowBlobsMap[key] = arrowProto.data
}
})

return reconstructMixedData(jsonData, arrowBlobsMap)
}
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
@sfc-gh-bnisco sfc-gh-bnisco merged commit dc644a5 into develop Oct 24, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:internal PR changes only affect internal code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants