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

[Bug?]: Redirect thrown from action cause resulting page to not see search params correctly #1500

Closed
2 tasks done
apatrida opened this issue May 23, 2024 · 7 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@apatrida
Copy link

apatrida commented May 23, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

In an action to a form, throw a redirect('/whateva?q=123') and the component that receives the routing will not see the search parameter even though the browser URL is updated. Directly loading the same URL will see the search parameter.

const formAction = action(async(()=>{
   ...
   throw redirect('/whateva?q=123')
});

// ...use formAction in a form


export default function WhatevaRoute(props: RouteSectionProps) {
...
	const [searchParams] = useSearchParams();
	const searchFor = () => searchParams.q?.trim() ?? undefined;
	const hasSearch = () => {
	    const searchTerm = searchFor();
	    return searchTerm && searchTerm.trim().length > 0;
	  };
	
	console.debug('DEBUG: HAS SEARCH', searchFor(), hasSearch());
	onMount(() => {
	  console.debug('DEBUG (effect): HAS SEARCH', searchFor(), hasSearch());
	});

logs undefined, undefined

Expected behavior 🤔

After redirect to /whateva?q=123 the above code should log 123, true but instead is undefined, undefined Refresh then shows the correct search params.

Steps to reproduce 🕹

Steps:

  1. create form action with redirect to a page using search params in the URL (i.e. /whateva?q=123
  2. in the /whateva route add a component that logs the useSearchParams().q
  3. Go to the form and cause the redirect
  4. note that the value is wrong on redirect, but correct on refresh of same url

Context 🔦

Note: my router is from a file based route (i.e. /routes/login.tsx) to a route that is defined in manual route structure (i.e. <Route path={"/whateva"} component={WhatevaRoute} />)

Your environment 🌎

solid-start 1.0.0
solidjs/router 0.13.3
@apatrida apatrida added the bug Something isn't working label May 23, 2024
@apatrida
Copy link
Author

In this test case above, it works. But in a fuller app it does not. Trying to improve the test case.

@apatrida
Copy link
Author

I make simple cases and doesn't happen. I try in full app and it happens in runs yes, then runs no.

@boehs
Copy link
Contributor

boehs commented May 23, 2024

Yeah I was going to say that I couldn't replicate it here. We can't help without an actual replication or anything else to go off

@apatrida
Copy link
Author

Wondering if it is a race condition. I put a sample in the same route level in my real app and doesn't reproduce. Do the larger page and it does, but goes in runs of yes/no.

@apatrida
Copy link
Author

Ah, the one that fails is lazy loaded route. Checking that.

@apatrida
Copy link
Author

I found that in one load function for the route it called useSearchParams() which might have errored out the load function, as I'm not sure if that is available there. I get random errors using that in load function instead of using the RouteLoadFuncArgs.location which is what I intended. But the component did use useSearchParams() which should be fine.

more testing...

@apatrida
Copy link
Author

closing for now unless it comes back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants