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

chore: Set router basename to simplify paths in /ui #5004

Merged
merged 1 commit into from
Mar 2, 2025

Conversation

peruukki
Copy link
Contributor

@peruukki peruukki commented Feb 4, 2025

What this PR does / why we need it:

Sets the React Router basename to avoid repeating the PUBLIC_URL environment variable.

Which issue(s) this PR fixes:

This is pretty much a re-do of #3541 but with only internal changes. Related short discussion started in #3514 (comment).

Misc

I verified that the environment variable still works by starting the app with PUBLIC_URL=/feast-ui yarn start (also PUBLIC_URL=http://localhost:3000/feast-ui yarn start somehow works):
feast-ui-prefix

Note: I originally included some changes that affected the behavior (see discussion below), but eventually decided to keep this as purely refactoring, and make other kinds of improvements separately.

@peruukki peruukki requested a review from a team as a code owner February 4, 2025 06:18
@peruukki peruukki force-pushed the ui-router-basename branch 2 times, most recently from 74278f9 to 34d2bb0 Compare February 4, 2025 06:24
@HaoXuAI
Copy link
Collaborator

HaoXuAI commented Feb 4, 2025

This is a really nice feature, thx!

@redhatHameed
Copy link
Contributor

just checking is there anything required for updating the readme document for this change ?

@HaoXuAI
Copy link
Collaborator

HaoXuAI commented Feb 4, 2025

yeah might be better to write something here: https://docs.feast.dev/reference/alpha-web-ui

@redhatHameed
Copy link
Contributor

@peruukki can you see if any document needs update for this change-> https://github.com/feast-dev/feast/blob/master/docs/reference/alpha-web-ui.md

@peruukki peruukki force-pushed the ui-router-basename branch 3 times, most recently from 5b700be to 2c98539 Compare February 4, 2025 21:04
@peruukki
Copy link
Contributor Author

peruukki commented Feb 4, 2025

I added a subsection about the new prop, see it rendered in alpha-web-ui.md and ui/README.md. (I also did tiny other tweaks.)

@peruukki
Copy link
Contributor Author

peruukki commented Feb 4, 2025

It now occurred to me that this is actually a breaking change if you were using Feast UI as a module in your app and using the PUBLIC_URL environment variable: now you need to explicitly pass its value in the basename prop like we do in ui/src/index.tsx since the FeastUI component no longer references the environment variable.

So maybe that should be mentioned in the release notes? Let me know if you want me to change e.g. the PR title prefix from "chore" to something else due to this.

@HaoXuAI
Copy link
Collaborator

HaoXuAI commented Feb 6, 2025

erences the environment variable.

So maybe that should be mentioned in the release notes? Let me know if you wan

Is there a way to make PUBLIC_URL still works in environment variables for feast?

Copy link
Member

@franciscojavierarceo franciscojavierarceo left a comment

Choose a reason for hiding this comment

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

hold

@franciscojavierarceo
Copy link
Member

erences the environment variable.
So maybe that should be mentioned in the release notes? Let me know if you wan

Is there a way to make PUBLIC_URL still works in environment variables for feast?

+1 @peruukki any chance we can investigate this?

@peruukki
Copy link
Contributor Author

peruukki commented Feb 6, 2025

To clarify, this doesn't remove the possibility to use PUBLIC_URL. But if you are using Feast UI as a module, you now need to pass that value to the FeastUI component via its basename prop.

If you were only defining the PUBLIC_URL environment variable to use it inside the FeastUI component, you can now remove it. If you want to keep using it, you'll need to make a change like this in your index.tsx file (similarly to the ui/src/index.tsx changes in this PR):

@@ -3,16 +3,19 @@ import ReactDOM from 'react-dom/client';
 
 import './index.css';
 import FeastUI from '@feast-dev/feast-ui';
 import '@feast-dev/feast-ui/dist/feast-ui.css';
 
+const basename = process.env.PUBLIC_URL ?? '';
+
 const root = ReactDOM.createRoot(document.getElementById('root')!);
 root.render(
   <StrictMode>
     <FeastUI
+      basename={basename}
       feastUIConfigs={{
-        projectListPromise: fetch(`${process.env.PUBLIC_URL ?? ''}/projects-list.json`, {
+        projectListPromise: fetch(`${basename}/projects-list.json`, {
           headers: {
             'Content-Type': 'application/json',
           },
         }).then((res) => {
           return res.json();

(And now looking at that, we could use basename in defaultProjectListPromise too, so you wouldn't always need to provide a custom projectListPromise just for this, but maybe that's for another pull request. 😄)

I would prefer not to use environment variables inside the FeastUI component because they are quite a hidden way to pass values and give you less flexibility on how you define the value, and I don't see why we couldn't use a regular prop here. But I also understand that we may want to preserve backwards compatibility. In that case, we can either:

  1. Not add the basename prop to FeastUI, and we keep referencing PUBLIC_URL inside it. We can still keep the benefits of referencing it only in one place and in a way that doesn't cause an error if you haven't defined a process.env global; these were my main motivation for these changes anyway.
  2. Have two ways of setting the basename, either via this new prop or via the PUBLIC_URL environment variable like before. And if both are defined, I would give the prop precedence since it's more local.

@HaoXuAI
Copy link
Collaborator

HaoXuAI commented Feb 7, 2025

To clarify, this doesn't remove the possibility to use PUBLIC_URL. But if you are using Feast UI as a module, you now need to pass that value to the FeastUI component via its basename prop.

If you were only defining the PUBLIC_URL environment variable to use it inside the FeastUI component, you can now remove it. If you want to keep using it, you'll need to make a change like this in your index.tsx file (similarly to the ui/src/index.tsx changes in this PR):

@@ -3,16 +3,19 @@ import ReactDOM from 'react-dom/client';
 
 import './index.css';
 import FeastUI from '@feast-dev/feast-ui';
 import '@feast-dev/feast-ui/dist/feast-ui.css';
 
+const basename = process.env.PUBLIC_URL ?? '';
+
 const root = ReactDOM.createRoot(document.getElementById('root')!);
 root.render(
   <StrictMode>
     <FeastUI
+      basename={basename}
       feastUIConfigs={{
-        projectListPromise: fetch(`${process.env.PUBLIC_URL ?? ''}/projects-list.json`, {
+        projectListPromise: fetch(`${basename}/projects-list.json`, {
           headers: {
             'Content-Type': 'application/json',
           },
         }).then((res) => {
           return res.json();

(And now looking at that, we could use basename in defaultProjectListPromise too, so you wouldn't always need to provide a custom projectListPromise just for this, but maybe that's for another pull request. 😄)

I would prefer not to use environment variables inside the FeastUI component because they are quite a hidden way to pass values and give you less flexibility on how you define the value, and I don't see why we couldn't use a regular prop here. But I also understand that we may want to preserve backwards compatibility. In that case, we can either:

  1. Not add the basename prop to FeastUI, and we keep referencing PUBLIC_URL inside it. We can still keep the benefits of referencing it only in one place and in a way that doesn't cause an error if you haven't defined a process.env global; these were my main motivation for these changes anyway.
  2. Have two ways of setting the basename, either via this new prop or via the PUBLIC_URL environment variable like before. And if both are defined, I would give the prop precedence since it's more local.

ok I think that make sense. I like this feature because when I setup Superset it is very hard to have a ui prefix in the public URL. it would be convenient to have process.env.PUBLIC_URL works so that users can customize the web url.

@HaoXuAI
Copy link
Collaborator

HaoXuAI commented Feb 7, 2025

To clarify, this doesn't remove the possibility to use PUBLIC_URL. But if you are using Feast UI as a module, you now need to pass that value to the FeastUI component via its basename prop.
If you were only defining the PUBLIC_URL environment variable to use it inside the FeastUI component, you can now remove it. If you want to keep using it, you'll need to make a change like this in your index.tsx file (similarly to the ui/src/index.tsx changes in this PR):

@@ -3,16 +3,19 @@ import ReactDOM from 'react-dom/client';
 
 import './index.css';
 import FeastUI from '@feast-dev/feast-ui';
 import '@feast-dev/feast-ui/dist/feast-ui.css';
 
+const basename = process.env.PUBLIC_URL ?? '';
+
 const root = ReactDOM.createRoot(document.getElementById('root')!);
 root.render(
   <StrictMode>
     <FeastUI
+      basename={basename}
       feastUIConfigs={{
-        projectListPromise: fetch(`${process.env.PUBLIC_URL ?? ''}/projects-list.json`, {
+        projectListPromise: fetch(`${basename}/projects-list.json`, {
           headers: {
             'Content-Type': 'application/json',
           },
         }).then((res) => {
           return res.json();

(And now looking at that, we could use basename in defaultProjectListPromise too, so you wouldn't always need to provide a custom projectListPromise just for this, but maybe that's for another pull request. 😄)
I would prefer not to use environment variables inside the FeastUI component because they are quite a hidden way to pass values and give you less flexibility on how you define the value, and I don't see why we couldn't use a regular prop here. But I also understand that we may want to preserve backwards compatibility. In that case, we can either:

  1. Not add the basename prop to FeastUI, and we keep referencing PUBLIC_URL inside it. We can still keep the benefits of referencing it only in one place and in a way that doesn't cause an error if you haven't defined a process.env global; these were my main motivation for these changes anyway.
  2. Have two ways of setting the basename, either via this new prop or via the PUBLIC_URL environment variable like before. And if both are defined, I would give the prop precedence since it's more local.

ok I think that make sense. I like this feature because when I setup Superset it is very hard to have a ui prefix in the public URL. it would be convenient to have process.env.PUBLIC_URL works so that users can customize the web url.

@franciscojavierarceo seems good to go.

@peruukki peruukki force-pushed the ui-router-basename branch from 262cba8 to 78e429d Compare March 2, 2025 07:35
@peruukki
Copy link
Contributor Author

peruukki commented Mar 2, 2025

@franciscojavierarceo I reduced the scope of this PR and made it purely refactoring, i.e. no externally visible changes. It's better to make such changes separately after this.

@franciscojavierarceo franciscojavierarceo merged commit 9265cfc into feast-dev:master Mar 2, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants