Shopify / shopify-app-js

MIT License
275 stars 107 forks source link

[shopify-app-remix] Form submissions redirects broken in proxied remix app #1073

Open vanceism7 opened 3 months ago

vanceism7 commented 3 months ago

Issue summary

Before opening this issue, I have:


I'm working on a shopify remix app, which is using the shopify proxy on the store front side of things to add some additional functionality. In my work, I think I've discovered that form submission actions seem to be broken because of the proxy url rewrites.

Here's my minimal reproduction

export async function loader({ request }: LoaderFunctionArgs) {
  return json({ appUrl: process.env.SHOPIFY_APP_URL });
}

const FooPage = () => {
  const { appUrl } = useLoaderData<typeof loader>();

  return (
    <AppProxyProvider appUrl={appUrl}>
      <main>
        // You can also use plain `Form` here, the result is the same
        <AppProxyForm action="/apps/proxy/foo" method="post">
          <button type="submit">Click me</button>
        </AppProxyForm>
      </main>
    </AppProxyProvider>
  );
};

export default FooPage;

export async function action({ request }: ActionFunctionArgs) {
  return null;
  // or return redirect("/")
  // Really you can return anything here, the result is the same
}

Expected behavior

Actual behavior

In all of the above expected scenarios, instead of the page remaining unchanged or redirecting properly, the store url always gets rewritten to the url of my actual app.

E.g: (If my app url is myapp.com)

Other notes

This issue seems to specifically happen with form submission actions.

For example, the following loader function works as expected

export const loader: LoaderFunction = async () => {
  return redirect("/")
};

This function will successfully redirect me to foo.myshopify.com.

Also, if I call the action function manually using a fetch call, this also gets back the response fine without any redirection.

But any call within the context of a form submission redirects away from the shopify store over to my app's direct url. This is specifically a big issue when using libs like conform, which use the form action to run validation on the server side, causing the form to break immediately on tabbing from one form input to another

matteodepalo commented 3 months ago

Hi @vanceism7, thank you for opening this issue, the team will take a look.

Xmaster6y commented 3 months ago

Seconding this. To complement:

anasdevv commented 2 months ago

Any progress with the findings? This really gives me headaches..

github-actions[bot] commented 1 week ago

We're labeling this issue as stale because there hasn't been any activity on it for 60 days. While the issue will stay open and we hope to resolve it, this helps us prioritize community requests.

You can add a comment to remove the label if it's still relevant, and we can re-evaluate it.