Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kmcgrady
Copy link
Collaborator

Describe your changes

We introduced error links with Google/ChatGPT, but we have found that this does not work well in production scenarios for multiple reasons. We have decided to only show these links while the url is localhost (indicating development mode).

GitHub Issue Link (if applicable)

closes #10924

Testing Plan

  • JS unit tests updated or added.

Contribution License Agreement

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

@kmcgrady kmcgrady added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Mar 31, 2025
@kmcgrady kmcgrady requested a review from Copilot March 31, 2025 15:47
@snyk-io
Copy link
Contributor

snyk-io bot commented Mar 31, 2025

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

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 31, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-10971/streamlit-1.44.0-py3-none-any.whl
🕹️ Preview app pr-10971.streamlit.app (☁️ Deploy here if not accessible)

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 restricts the display of error links (to Google/ChatGPT) to development mode by checking if the app is running on localhost. Key changes include:

  • Introducing a centralized isLocalhost function in the utils package.
  • Updating tests for isLocalhost and ExceptionElement to reflect the new logic.
  • Removing duplicate implementations in the deploymentInfo module and updating imports accordingly.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
frontend/utils/src/uri/index.ts Adds centralized isLocalhost utility function.
frontend/utils/src/uri/index.test.ts Updates tests to cover isLocalhost behavior (note a potential issue with hostname values).
frontend/lib/src/components/elements/ExceptionElement/ExceptionElement.tsx Updates the component to conditionally render error links based on isLocalhost.
frontend/lib/src/components/elements/ExceptionElement/ExceptionElement.test.tsx Adds tests for proper rendering of error links based on hostname.
frontend/app/src/showDevelopmentOptions.ts Refactors import to use the new isLocalhost utility function.
frontend/app/src/App.tsx Updates import for isLocalhost and maintains consistency across the app.
frontend/app/src/util/deploymentInfo.ts & deploymentInfo.test.ts Removes redundant local implementations of isLocalhost.
Comments suppressed due to low confidence (1)

frontend/lib/src/components/elements/ExceptionElement/ExceptionElement.test.tsx:105

  • The test description 'should not render exception links for localhost' is misleading because it tests the behavior for non-localhost hostnames. Consider renaming it to 'should not render exception links for non-localhost'.
it("should not render exception links for localhost", () => {

})

it("returns true given 127.0.0.1", () => {
window.location.hostname = "localhost"
Copy link

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

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

In the test case for 'returns true given 127.0.0.1', the hostname is incorrectly set to "localhost". Change it to "127.0.0.1" to accurately test the intended behavior.

Suggested change
window.location.hostname = "localhost"
window.location.hostname = "127.0.0.1"

Copilot uses AI. Check for mistakes.
Comment on lines 84 to 94
beforeEach(() => {
originalLocation = window.location
// Replace window.location with a mutable object that otherwise has
// the same contents so that we can change hostname below.
// @ts-expect-error
delete window.location
})
afterEach(() => {
// @ts-expect-error
window.location = originalLocation
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Rather than directly mutating window.location and having to ignore Typescript, we can leverage vitest mocks:

    let windowSpy: MockInstance

    beforeEach(() => {
      originalLocation = window.location
      windowSpy = vi.spyOn(window, "location", "get")
    })

    afterEach(() => {
      windowSpy.mockRestore()
    })

And the per-test assignments can be:

      windowSpy.mockImplementation(() => ({
        ...originalLocation,
        hostname: "localhost",
      }))


describe("isLocalhost", () => {
const { location: originalLocation } = window
beforeEach(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Same comment here as above

@kmcgrady kmcgrady merged commit 15dc2c2 into develop Mar 31, 2025
33 checks passed
@kmcgrady kmcgrady deleted the fix/error-links branch March 31, 2025 18:57
sfc-gh-bnisco pushed a commit that referenced this pull request Mar 31, 2025
## Describe your changes

We introduced error links with Google/ChatGPT, but we have found that
this does not work well in production scenarios for multiple reasons. We
have decided to only show these links while the url is localhost
(indicating development mode).

## GitHub Issue Link (if applicable)

closes #10924

## Testing Plan

- JS unit tests updated or added.

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation 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.

Make error link buttons to Google / ChatGPT optional

3 participants