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
Form submitting to incorrect routes #14
Comments
We have an issue, but it is related to a |
I recommend being explicit with your |
Looking at your Stackblitz, it looks as though the actions are being invoked properly. I think I may be misunderstanding the issue. Could you explain in more detail how each action is supposed to function? I've attached a video of the behavior I am seeing. CleanShot.2022-11-03.at.21.17.23.mp4EDIT:: Disregard this, I tweaked the example you had a bit and was able to create a reproduction of the issue. Can find a modified Stackblitz here: https://stackblitz.com/edit/node-7u4xmy?file=app/flat/_site._index.tsx |
I'm also experiencing this issue, except with a One thing I noticed is that when running I'll put together a reproduction for you. |
Here's the
And here's the
NOTE: I noticed that StackBlitz isn't completely reliable in running things correctly so I suggest downloading and running locally. Also one thing I noticed is the form that's actually rendered differs in the two examples. In the one that works, it includes I should also mention that even if I disable JavaScript and add the |
Interesting. Thanks for the repro. I'm finishing up my Remix Conf presentation, but I will get to this ASAP. |
I ran into this same issue when upgrading and found that the breakage is specifically tied to upgrading from Remix
(Kent's original examples used It's not immediately clear to me what change in |
Thanks for the research. I was surprised when this started breaking, as I haven't had any issues in my app which has over 100 routes, but I also haven't updated to the latest yet either. Anyway, I will get to the bottom of this. Remix flat routes should generate the same routing structure as the conventional routes. |
I found the problems. First is a bug in my route generation, but the other is a bug in Remix in how it matches the index route. It was checking if the URL ends in Here's the patch for Remix. I'll be updating the flat routes package. diff --git a/node_modules/@remix-run/server-runtime/dist/server.js b/node_modules/@remix-run/server-runtime/dist/server.js
index 5ac2304..58e39f3 100644
--- a/node_modules/@remix-run/server-runtime/dist/server.js
+++ b/node_modules/@remix-run/server-runtime/dist/server.js
@@ -503,7 +503,7 @@ function isIndexRequestUrl(url) {
function getRequestMatch(url, matches) {
let match = matches.slice(-1)[0];
- if (isIndexRequestUrl(url) && match.route.id.endsWith("/index")) {
+ if (isIndexRequestUrl(url) && match.route.index) {
return match;
} |
One other Remix patch. This time it's to fix the index handling for the Form action. Again Remix is checking for ending in diff --git a/node_modules/@remix-run/react/dist/esm/components.js b/node_modules/@remix-run/react/dist/esm/components.js
index e884e7b..56ddff4 100644
--- a/node_modules/@remix-run/react/dist/esm/components.js
+++ b/node_modules/@remix-run/react/dist/esm/components.js
@@ -746,6 +746,7 @@ FormImpl.displayName = "FormImpl";
*/
function useFormAction(action, // TODO: Remove method param in v2 as it's no longer needed and is a breaking change
method = "get") {
+ let { manifest }= useRemixEntryContext()
let {
id
} = useRemixRouteContext();
@@ -760,7 +761,7 @@ method = "get") {
search,
hash
} = resolvedPath;
- let isIndexRoute = id.endsWith("/index");
+ let isIndexRoute = manifest.routes[id].index
if (action == null) {
search = location.search; |
I submitted a PR to fix the invalid index handling. remix-run/remix#4560 |
Thank you! |
While the PR is being reviewd, I'm going to update flat routes to add the |
@nakleiderer @lukebowerman @puchesjr @shadyendless Please try latest v0.4.8. I added a workaround in the package itself until the PR bug fix has been merged into Remix. Thanks everyone for your patience. |
After migrating to this library, my forms are submitting to incorrect routes.
Here's a repro (the README has a lot more detail): https://stackblitz.com/edit/node-kh9dmu?file=README.md
The text was updated successfully, but these errors were encountered: