-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
fail when render status: :unprocessable_entity #29
Comments
Sorry, I'm not a ruby developer but I'm not totally sure this is the right repository. Unless we are saying that it would work as expected with only alpine and without the turbolinks bridge. By the way, could you post the generated html please? Thanks |
<div x-data="{text: 'demo' }">
<div x-text="text">demo</div>
</div>
<form action="/posts" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="ufX5eM9Ld2hGYyia8R4zGAS_wFvwNHzv2-CsUV0UKuR1bEpPhfuqfXDgtHTV_gDecNDNzLV-ipvSCyWkzevp-w">
<div class="form-group">
<label for="post_title">
<input type="text" name="post[title]" id="post_title" />
</div>
<div class="form-group">
<input type="submit" name="commit" value="Save post" class=" btn btn-primary"/>
</div>
</form> After submit form and sever return 422 status, alpine fail to init all data and events. |
Thanks, I'll have a look in the next few days and see if i can replicate. |
Thanks, i modified alpine-turbo-drive-adapter/src/bridge.js Line 89 in 9bbfe00
document.addEventListener('turbo:render', initCallback) can make it works, I'm not sure if that's the right way.
|
I'll need to have a look. In Turbolinks, render gets called multiple times when you have cached previews which is not the best for Alpine, maybe it has changed in Turbo. It seems weird that it calls render but it doesn't call load after maybe I can ask the guys at Turbo. |
there's a |
Thanks, you're right, i'll try again later. |
if the code use turbo frames, it replaces the content and triggers the alpine update. |
Thanks for your reply, yes, the |
@SimoTod
If we use For anyone looking for a quick workaround till this is resolved, try this:
|
@KostasKostogloy I know but I would really like Turbo to fix their bug or at least clarify the behaviour because it's not consistent/correct. They should either not refresh the page when there is an error or trigger a load event IMO. If you look at the bug above, people have the same issues with other frameworks, it's not just an alpine thing. Out of curiosity, is there a reason why you don't use turbo frames with forms? It seems to be the standard way to do it. To clarify, the problem with render is that it gets called twice when you visit a cached page so, with the solution above, it will get called 3 times, not a big issue but something to be aware of. |
@SimoTod the main reason is that we display flash messages on the page and if we enclosed the form in a frame those would be outside of it (and not get displayed). Problem's context: You want a form to submit with So our options were:
So there was no perfect solution and since 4. did not introduce any perceptible slowdown, we opted for that. |
Thanks for your feedback. I need to think about that before switching to turbo:render. 4 works but it's based on the assumption that an internal behaviour of Turbo won't ever change (I don't think they state anywhere that a 422 refreshed the page) so maybe keep an eye on it until they tag the first stable release. |
Better late than never. @nyrf @KostasKostogloy or anyone else following the bug report. |
@SimoTod thanks for your hard work 🙇♂️ I am going to test this in the next few days and get back to you. |
@SimoTod Great, thanks. I've tested and it works. |
Thanks for confirming @nyrf |
Thanks for the fix @SimoTod. I've installed v1.0.3 of alpine-turbo-drive-adapter (upgraded from v1.0.2) and performed some initial testing myself - the problems we were having around this issue look to be fixed in Firefox (v88) and Chrome (v90). However, for me at least, the problem still seems to exist in Safari (Safari v14.1, MacOS Big Sur 11.3). Is anyone experiencing this issue in Safari only? (Note that the workaround fix suggested in #29 (comment) does "fix" the issue in all browsers that I've tested with, so perhaps there's some quirk of Safari that needs to be taken account of?) |
The problem with using render is that it might break the page in other edge cases introducing flickerings, etc. I'll check safari tomorrow. |
@rickclare It took less than expected. I was able to replicate it in Safari. |
@SimoTod that's great, thank you for jumping on the fix so quickly. I'll do some more testing tomorrow to double check v1.0.4 in the browsers that I have access to (everything popular apart from MS Edge) Thanks again. |
Hi @SimoTod I've performed some more testing with v1.0.4 If it helps with diagnosis - my scenario is a simple user-registration page (run-of-the-mill Ruby-on-Rails MVC), which has the following markup: <form action="/register" accept-charset="UTF-8" method="post">
<input type="hidden" name="authenticity_token" value="0j2wnYnsareCIghBGUzTCF3qv5b51aq46Pi2E2pYxHyN4vx8u0PB1JXFBzc8VNBXxSKmA3OKcoAXsHDyoxiqrw==">
<label for="member_email">Email</label>
<input id="member_email" name="member[email]" type="email">
<label for="member_password">Password</label>
<input id="member_password" name="member[password]" type="password">
<button type="submit">Register</button>
</form>
<div class="app-environment"
x-data="{ visible: true }"
x-on:click="visible = false"
x-show="visible">
Development
</div>
I'm happy to keep testing any fixes that you release. I would love to help with the fix itself, but my javascript-fu isn't advanced enough to be able to suggest a solution. |
@rickclare I'm not a rail developer so I would need the response from the form submission if you can kindly send it over (The example I built in php is working okay in safari) You can get it from safari > right click > inspect element (you need to enable it in preferences if you haven't yet) > network tab > your request. I need the content of both the preview tab and headers tab. Thanks |
@SimoTod No problem, here is the response from Safari's Network tab: Headers:
Preview: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover">
<meta charset="UTF-8" content="PTgQOh91D15hPgI3N0QiESAgLhsNBRdHuKqBIGDk7kThCicPqwYnUVAr" csrf-param="authenticity_token" method-param="_method" name="csrf-token">
<link data-turbo-track="reload" rel="stylesheet" href="/css/app.css">
<script data-turbo-track="reload" defer src="/js/app.js"></script>
</head>
<body>
<form action="/register" accept-charset="UTF-8" method="post"><input name="authenticity_token" type="hidden" value="PTgQOh91D15hPgI3N0QiESAgLhsNBRdHuKqBIGDk7kThCicPqwYnUVAr">
<div class="notification is-danger">
Something went wrong! Please check the errors below
</div>
<label for="member_email">Email address</label>
<input id="member_email" name="member[email]" type="email" value="[email protected]">
<label for="member_password">Password</label>
<input id="member_password" name="member[password]" type="password">
<span class="is-danger">should be at least 12 characters</span>
<button class="button is-primary" data-form-target="button" type="submit">Register</button>
</form>
<div class="app-environment"
x-data="{ visible: true }"
x-on:click="visible = false"
x-show="visible">
Development
</div>
</html> |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I believe edge doesn't support |
@rickclare So... The UMD version (the one that is served by the CDN too) works correctly in Safari but the ESM version doesn't. I assume that, if you instruct your bundler to generate a file compatible with edge and safari, it would work. However, I've recompiled with slightly different settings and the ESM version seems to behave now. For just a few bytes more, I'm happy to include an ESM version that works out of the box with Safari. I'll run a few more tests and I'll release it over the weekend with the other pending PR to support turbo-streams. It's going to be 1.1.0 |
@SimoTod thank you for your perseverance with this. I'll find some time tomorrow to test out the new version and report back. Have a great weekend. |
It will likely be Sunday. I decided to run a few more tests for both features first. 👍 |
Unfortunately, the Safari was still happening (some times was working and sometimes wasn't). I believe something to do with the submit-end event being triggered on the document before the page update and Safari ignoring the delayed callback once the DOM was updated. |
@SimoTod I've retested the scenario where I had the original issue, using v1.1.0, and the problem is no longer there (i.e. my Alpine markup is working perfectly after submitting a form that returns a 422 response) I successfully tested with the following browsers: ✅ Safari v14.1 (MacOS) Thanks again for your patience and getting this fixed so quickly, nice job. |
new.html.erb
when title is blank and render 422 status, alpine won't work.
The text was updated successfully, but these errors were encountered: