Comments (5)
Good catch, we should fix that
from fresh.
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.
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.
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.
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)
- Inside `f-partial-nav` the server-side redirects do not work. HOT 1
- PM2 doesn't seem to work with Fresh HOT 8
- Deno Fresh is unusable in production with Signal HOT 1
- Input with type=submit inside partial does not submit its own value HOT 3
- Incorrect processing of URLSearchParams when submitting forms inside f-nav-client HOT 1
- Bug: `_middleware.tsx` doesn't run before `_500.tsx` or `_error.tsx`
- Adding a <meta name="viewport"> tag using the <Head> component adds a new tag instead of replacing the default one HOT 1
- Why does/What causes Partials to not work sometimes? HOT 2
- Consider bringing back buildStart + renderAsync or something similar
- TypeError: Cannot read properties of null (reading '__hooks') HOT 2
- bug: fresh islands are broken with preact 1.22.1
- [[email protected]] File-based routing has inconsisten middleware behavior
- [[email protected]] Ability for plugins to serve static assets
- [[email protected]] `app.config.mode === "production"` during development
- [[email protected]] Cannot declare `RouteConfig` for plugin-injected routes
- [[email protected]] Islands under `routes/(_islands)/...` won't be detected as islands HOT 1
- `_layout.tsx` is not used in `_error.tsx`
- Can not use react-select
- iOS15 Partials link do not work HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fresh.