Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Redirect triggers page reload in deployed version when redirecting with redirecting to a full URL #4656

Closed
cjkooij opened this issue Nov 21, 2022 · 1 comment

Comments

@cjkooij
Copy link

cjkooij commented Nov 21, 2022

What version of Remix are you using?

1.7.4

Steps to Reproduce

Have an action function with a redirect in which you redirect to to a full URL with the protocol/host.

Expected Behavior

Page does not reload, as it does while running the code locally.

Actual Behavior

Page does reload (when deployed).

Ryan's comment:
"we have code to make sure to do a window.location = instead of history.pushState in that case
we should add some code to be less naive and check if the window.origin is the same, too
"

@brophdawg11
Copy link
Contributor

👋 Hey! I think this is the same thing being asked for in this Proposal so I'm going to close this out in favor of that if you'd like to upvote that proposal.

If you need a workaround in the short term, I'd probably just do it through actionData/useEffect which is effectively what Remix does under the hood for different origins as is.

export function action() {
  return json({ hardReloadUrl: 'https://www.currentorigin.com/whatever' });
}

export default function Component() {
  let actionData = useActionData();

  React.useEffect(() => {
    if (actionData?.hardReloadUrl && typeof window !== 'undefined') {
      window.location.replace(actionData.hardReloadUrl);
    }
  }, [actionData]);

  return <Form method="post>...</Form>
}

@brophdawg11 brophdawg11 removed their assignment Jan 23, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants