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

Fix UrlSelect trigger value reset for non expo router projects #873

Merged

Conversation

p-malecki
Copy link
Contributor

@p-malecki p-malecki commented Dec 20, 2024

This PR changes the UrlBar behaviour in projects not using Expo Router navigation.
When the user intends to close the preview by pressing the goHome button (or reload), the UrlSelect's trigger value needs to be reset to a placeholder ("/").

Additionally, this update disables the goBack button for projects that do not use Expo Router.

How Has This Been Tested:

  • Tested on expo-router and react-native-76 apps.
Before After
Screen.Recording.2024-12-20.at.18.45.00.mov
Screen.Recording.2024-12-20.at.18.35.50.mov

Copy link

vercel bot commented Dec 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
radon-ide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 7, 2025 10:52am

value: string;
onValueChange: (newValue: string) => void;
recentItems: UrlItem[];
items: UrlItem[];
disabled?: boolean;
}

function UrlSelect({ onValueChange, recentItems, items, value, disabled }: UrlSelectProps) {
function UrlSelect({ onValueChange, recentItems, items, key, value, disabled }: UrlSelectProps) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe that it only has been added in React 19 that you can receive key prop like this. I don't think in the current version in propagates down to the component

@@ -35,7 +36,7 @@ function UrlSelect({ onValueChange, recentItems, items, value, disabled }: UrlSe
};

return (
<Select.Root onValueChange={handleValueChange} value={value} disabled={disabled}>
<Select.Root onValueChange={handleValueChange} key={key} value={value} disabled={disabled}>
Copy link
Member

Choose a reason for hiding this comment

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

It should be enough to do something along these lines, instead of having the whole logic for urlSelectKey in the parent component:

<Select.root key={value ? "has-value : "no-value"}>

@@ -117,8 +130,9 @@ function UrlBar({ disabled }: { disabled?: boolean }) {
}}
recentItems={recentUrlList}
items={sortedUrlList}
value={urlList[0]?.id}
disabled={disabledAlsoWhenStarting || urlList.length < 2}
key={urlSelectKey}
Copy link
Member

Choose a reason for hiding this comment

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

setting this here is enough to re-mount the whole component. It doesn't have to be accessed in the underlying component

@p-malecki
Copy link
Contributor Author

I’ve removed the urlSelectKey state and key prop from UrlSelect, which were added in a previous PR version. Setting setUrlSelectValue to an empty string is sufficient to reset the trigger value of UrlSelect to a placeholder.

Copy link
Collaborator

@filip131311 filip131311 left a comment

Choose a reason for hiding this comment

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

I approve this changes adding some inline comments to adres #887.

@@ -103,6 +109,9 @@ function UrlBar({ disabled }: { disabled?: boolean }) {
<IconButton
onClick={() => {
project.goHome("/{}");
if (!isExpoRouterProject) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like this being placed as a dependency of a user action as we'll have to remember to update it every time we add a new navigation option I would much rather have wrapper.js send an event every time application is loaded and then some global logic would handle setting the correct navigation state to the url bar.

Having said that I think we should move most of the logic in this file to the extension code to allow passing state between diffrent panel locations any wayand my suggestion will be easier to active then.

@p-malecki p-malecki merged commit b6ad1a4 into main Jan 10, 2025
4 checks passed
@p-malecki p-malecki deleted the @p-malecki/fix-navigation-for-non-expo-router-projects branch January 10, 2025 08:25
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.

3 participants