-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Opaque redirect handler results in message "Error: 405 Method Not Allowed" in Blazor app #51118
Comments
This is a really interesting bug because it was hard to track down, and having done so, feels like a pretty fundamental issue with enhanced navigation. So fundamental that I couldn't quite see how other frameworks would avoid the equivalent issue, so I tried to repro it in SvelteKit's The core thing is that when you use the HTML History APIs,
You might think (as I first did) the framework should solve this by changing the order of operations. It could defer the Possible solutionsI'm not convinced there is any solution for the general version of this problem, which is that code might assume the current URL corresponds to content in the page, but that's not always true. In the special case of this problem where the user submits a
My suggestion is we take the second option there, since AFAIK we are in a good position to do that. SSR already detects when it is rendering a |
Agree with your suggested change and IIRC it matches what we did in Web Forms and MVC. I'll try working around the issue by manually setting the form action to the current URL server side when the form is rendered until a framework fix lands. |
We are doing: |
Workaround for dotnet/aspnetcore#51118. Can remove once that issue's fix flows to builds we're using.
Workaround for dotnet/aspnetcore#51118. Can remove once that issue's fix flows to builds we're using.
This change updates the server rendering logic to always emit an absolute URL for a form action when none is specified explicitly. ## Description When as part of rendering a form, the developer does not explicitly add an `action` attribute, the framework will automatically generate one with the value of the current request URL. Fixes #51118 ## Customer Impact When enhanced navigation is active, the URL might change while an update to the page is in progress. In such situations, if the user clicks a button and submits a form, the form might incorrectly post to the wrong URL, as the page URL might have already been updated. Given that when the URL updates on the document is not a behavior, we have control over, we have to account for this, and to prevent it, we make sure that we always generate forms with an action attribute, which is unambiguous. ## Regression? - [ ] Yes - [X] No [If yes, specify the version the behavior has regressed from] ## Risk - [ ] High - [ ] Medium - [X] Low The fix is to detect forms without an `action` attribute and emit it to the current URL. This is correct in all cases and is unambiguous. ## Verification - [x] Manual (required) - [X] Automated ## Packaging changes reviewed? - [ ] Yes - [ ] No - [x] N/A ---- ## When servicing release/2.1 - [ ] Make necessary changes in eng/PatchConfig.props
Repro app: https://github.com/DamianEdwards/BlazorFormFun
.NET SDK version: 8.0.100-rc.2.23472.8
I have a Blazor app that's built to simulate an online store, listing items from a catalog, with the capability to add items to a cart/basket. The app is using Blazor SSR with streaming rendering, enhanced navigation & form handling. There is no interactive rendering enabled. Calls to load products, add an item to the cart, get the current cart item count, etc. are async and introduce async delay in order to simulate remote call processing. The availability of the cart itself is delayed to simulate only showing cart UX if the cart service can be successfully called.
When running the application and rapidly clicking the "Add to cart" buttons, an error can be shown in the browser. Note it can take dozens of clicks to reproduce the issue. Opening the browser dev tools network window can sometimes reduce the number of clicks required to reproduce the issue.
I've tried to reduce the repro but this is as far as I could go while still having the issue occur.
The text was updated successfully, but these errors were encountered: