-
Notifications
You must be signed in to change notification settings - Fork 4k
Only show links to google/ChatGPT if the site is localhost #10971
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
Conversation
🎉 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) |
✅ PR preview is ready!
|
There was a problem hiding this 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", () => {
frontend/utils/src/uri/index.test.ts
Outdated
| }) | ||
|
|
||
| it("returns true given 127.0.0.1", () => { | ||
| window.location.hostname = "localhost" |
Copilot
AI
Mar 31, 2025
There was a problem hiding this comment.
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.
| window.location.hostname = "localhost" | |
| window.location.hostname = "127.0.0.1" |
| 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 | ||
| }) |
There was a problem hiding this comment.
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",
}))
frontend/utils/src/uri/index.test.ts
Outdated
|
|
||
| describe("isLocalhost", () => { | ||
| const { location: originalLocation } = window | ||
| beforeEach(() => { |
There was a problem hiding this comment.
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
## 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.
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
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.