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

Rewrite useFormAction to respect basename #23

Closed
wants to merge 2 commits into from
Closed

Rewrite useFormAction to respect basename #23

wants to merge 2 commits into from

Conversation

unbiased-dev
Copy link

Not a lot of creative coding was done here, I just copied how react-router-dom implements useFormAction and adapted it to svelte.

Running yarn validate cypress gets stuck on

1: starting server using command "npm run integration:start"
and when url "[ 'http-get://localhost:3000/' ]" is responding with HTTP status code 200
running tests using command "npm run integration:test"

> react-router-dom-stub@0.0.0 integration:start
> vite build && vite preview --port 3000

vite v2.9.9 building for production...
✓ 49 modules transformed.
dist/index.html                  0.33 KiB
dist/assets/index.66c49214.css   0.06 KiB / gzip: 0.07 KiB
dist/assets/index.859b56ff.js    187.67 KiB / gzip: 60.71 KiB
  > Local: http://localhost:3000/
  > Network: use `--host` to expose

not sure what's up with that.

This same code inside my repo that uses react-router-svelte (directly in node_modules) fixes the problem described in this issue #22

Please verify all tests pass properly.

Link to useFormAction in react-router-dom for verification:
https://github.com/remix-run/react-router/blob/main/packages/react-router-dom/index.tsx#L873

Also link to useResolvedPath in react-router-dom where I copied how resolveTo is used:
https://github.com/remix-run/react-router/blob/bf5afbed559926ed35ac9180881c78c426a29230/packages/react-router/lib/hooks.tsx#L271

@brophdawg11
Copy link
Owner

@austincrim I'm going to leave this up to you. I've not bothered with relative routing or basename handling in the Vue adaptor yet because we plan to move that all out of react-router and into the @remix-run/router as part of remix-run/react-router#9588. Once that's done then the Vue/Svelet layers will be able to mostly "just work". Basename might just work out of the box, and relative routing should likely just require providing the calling routeId to router.navigate.

That said, if this is interesting in the short term and this patch works - feel free to merge it in and then you can rip it back out once the above lands in the Remix router 👍

@unbiased-dev unbiased-dev closed this by deleting the head repository Apr 16, 2023
@brophdawg11
Copy link
Owner

Just an FYI here - we just merged remix-run/react-router#10336 last week which moves relative routing/basename logic into @remix-run/router which should make it easier for the Vue/Svelte adapters to leverage. For full progressive enhancement support, Form/Link still need useFormAction/useHref to resolve relative/basename paths at render time but those can probably both use a version of normalizeTo from the router. Eventually I think we'll expose a public router.resolvePath() method that calls the (currently private) nornalizeTo method - but for now in this repo I'd probably just copy that function into the Vue/Svelte adapters

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