Skip to content
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

[ui] Lint against window.open #25912

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

hellendag
Copy link
Member

@hellendag hellendag commented Nov 13, 2024

Summary & Motivation

Stacking on #25909, lint against using window.open. This is because our current usage generally ignores any basePath value that might be in place in the app, e.g. a deployment path prefix in Dagster+.

The result is that opening the new tab may lead to a redirect that opens the path in a default fallback deployment, instead of the viewer's current deployment.

To avoid this, useOpenInNewTab prepends the basePath to the path value. I have added a lint rule to error on window.open usage and push users toward this hook instead.

How I Tested These Changes

TS, lint, jest.

Copy link
Member Author

hellendag commented Nov 13, 2024

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

@hellendag hellendag marked this pull request as ready for review November 13, 2024 22:23
Copy link

github-actions bot commented Nov 13, 2024

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-ela77t9iz-elementl.vercel.app
https://dish-window-open-lint.core-storybook.dagster-docs.io

Built with commit fa02329.
This pull request is being automatically deployed with vercel-action

@@ -1,12 +1,16 @@
import {useContext} from 'react';
import {useCallback, useContext} from 'react';

import {AppContext} from '../app/AppContext';

// Open a path in a new tab. Incorporates the base path to ensure that
// the link opens to the appropriate deployment.
export const useOpenInNewTab = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be a hook? Would prefer a regular function. Maybe we can move the basePath to be returned by extractCloudDagsterUISettings if it doesn't already have enough information to obtain it?

Copy link
Contributor

Choose a reason for hiding this comment

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

So currently we pass it to AppContext, maybe we can just use a global instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think we could do that. It seemed to me that a hook was fine since we're unlikely to be executing window.open outside of a React context, but I don't feel strongly about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think sometimes you might have logic that is divorced from React (eg: inside some helper function 2 levels deep) and it feels weird to require a component to thread the openInNewTab function that deep. It requires every function along the path to know that this functionality is nested inside which seems like a bad separate of concerns to me.

Base automatically changed from dish/fix-open-window-base-path to master November 14, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants