Giter VIP home page Giter VIP logo

Comments (5)

marvinhagemeister avatar marvinhagemeister commented on July 17, 2024

Good catch, we should fix that

from fresh.

Sleepful avatar Sleepful commented on July 17, 2024

It also breaks the URL history. Hitting the backwards button on the browser after clicking through some partials will yield the same result as mentioned above.

Is there a way to use partials without the redirect? Most of the time I just want to get some feedback from the server in HTML form, without any kind of redirect. If I want a redirect then I can set the headers myself on the server.

from fresh.

Sleepful avatar Sleepful commented on July 17, 2024

Here is a quick and dirty way around it, if you are using a <form> that creates a POST request and potentially retrieves a Partial, redirecting GET requests to a standard location makes it less jarring when using the refresh/backwards button on the browser.

export const config: RouteConfig = {
  skipAppWrapper: true, // Skip the app wrapper during rendering
};

export const handler: Handlers<unknown, State> = {
  GET(_req, _ctx) {
    // Currently it can't be avoided that Partials create a new URL in browser history, which is strange
    // when using the backwards and/or refresh button in the browser. To compensate, manually redirect GET requests.
    return new Response("", {
      status: 307,
      headers: { Location: "/" },
    });
  },

  async POST(req, ctx) {
	ctx.render() // renders the partial
  }

Caveat: anchor tags still want to use a GET request so that's more difficult to redirect server-side.

I believe the ideal would be to be able to avoid any kind of client-side URL history with an attribute or similar. For example:

<form f-partial="/some/partial" redirect-client="false">

If you like this idea, I would be happy to implement it and submit a PR, just LMK. 😄

from fresh.

marvinhagemeister avatar marvinhagemeister commented on July 17, 2024

Fresh will always redirect when using links. It doesn't redirect when using plain buttons without a form when the button has the f-partial attribute.

from fresh.

Sleepful avatar Sleepful commented on July 17, 2024

True, it makes sense that links redirect.

For <form> submissions the URL in the action attribute should take precedence over f-partial, right? In which case, if I don't want the submission to change the URL then I just give it the current URL on the action attribute.

I found this #2409 but I suppose I don't have it in my Fresh release right now.

from fresh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.