Releases: imacrayon/alpine-ajax
v0.5.0
This release is focused on giving you more control over the request and rendering lifecycle of Alpine AJAX. To that end we've introduced a few new attributes and events. We've also revamped focus management to make it easier to control keyboard focus as content on the page changes. Lastly, we've made Alpine AJAX 30% smaller by decoupling our DOM morphing logic into a separate, optional, plugin.
Breaking Changes
1. x-focus
removed in favor of x-autofocus
In most situations you can remove x-focus
and add x-autofocus
to the element what was being targeted by x-focus
. In more complex situations you can listen for the new ajax:merged
event and do whatever you want with focus in the event handler.
2. Decoupled Morph into a separate plugin
If your project is using x-merge="morph"
install the Alpine Morph Plugin and you're good to go. Using the "morph" strategy without first installing the plugin will now throw an exception and prompt you to install the plugin. Our documentation examples have been updated to include install instructions when the Morph Plugin is required.
Additions
- Added a global
headers
configuration option for customizing request headers for every request - Added
x-headers
and$ajax
headers
option for customizing request headers per request #49 - Added
ajax:merge
andajax:merged
events for customizing and reacting to merged content #62 - Added
x-autofocus
to declarative control keyboard focus after content is merged #56 - Added
x-target.nofocus
modifier to disable autofocus behavior
Fixes
- Changed the default
enctype
for AJAX requests toapplication/x-www-form-urlencoded
in #61 - Elements with
autofocus
will be focused after a merge #56 - Form submissions now respect
formaction
andformmethod
attributes #60 - Right clicking a link won't fire an AJAX requests #59
- History is updated before merging content so that relative URLs resolve correctly #58
Full Changelog: v0.4.3...v0.5.0
v0.4.3
v0.4.2
What's Changed
- Allow disabling AJAX per submit element by @bgilhome-now in #42
New Contributors
- @bgilhome-now made their first contribution in #42
Full Changelog: v0.4.1...v0.4.2
v0.4.1
v0.4.0
What's New
- Added History API support in #37
- Added View Transitions API support in #18
- Documented
x-Alpine-Request
header by @adamchainz in #36 - Fixed document typos by @hirasso in #38
New Contributors
- @adamchainz made their first contribution in #36
- @hirasso made their first contribution in #38
Full Changelog: v0.3.0...v0.4.0
v0.3.0
This release cleans up some edge case bugs, adds some global configuration options, and some new x-target
modifiers to handle redirect responses from your server.
Changed
x-target
now requires an accompanyingx-data
orx-init
, like a normal Alpine directive.<!-- Before --> <form x-target="..."> </form> <tbody> <a x-target="..."> </tbody> <!-- After --> <form x-init x-target="..."> </form> <tbody x-init> <a x-target="..."> </tbody>
x-arrange
has been renamed tox-merge
.
Do a find and replace in your project:x-arrange
->x-merge
.
Fixed
- Request data is correctly added to the URL query string when issuing a
GET
request using$ajax()
. - Response promises are unwrapped in the browser console when using the Mock Server.
- Removed a race condition that was causing flaky tests.
Added
x-target.nofollow
will cause the browser window to reload when a redirect (3xx) response is encountered. More info in the Handling Redirects section.- You can set global configuration options when importing Alpine AJAX in your code.
$ajax()
now acceptstarget
ortargets
as an option.$ajax()
now acceptsfollowRedirects
to change the redirect behavior of the AJAX request, just like thex-target.nofollow
modifier.- Source files are available in the NPM distribution now.
Full Changelog: v0.2.1...v0.3.0
v0.2.1
Fixed
aria-busy
is properly removed from targets after new content is appended.
Improved
- You'll see a friendly error message if you try to target an element that's not in the document. The previous message was very cryptic.
Full Changelog: v0.2.0...v0.2.1
v0.2.0
This is a big release, we've streamlined the Alpine AJAX API, and AJAX attributes are no longer inherited by child elements. These changes mean that your UIs will be more stable and less prone to unintended side-affects (you don't have to litter your HTML with x-noajax
anymore). The projects I've upgraded to v0.2 so far have ended up requiring slightly less code which is always a win. These API changes have also lead to some performance gains and opened the door for two new attributes: x-arrange
and x-focus
. Keep reading for full details on everything that has changed and guidance on upgrading from v0.1 to v0.2. While this release will require some code migration, it will improve the overall stability of your projects and make any future upgrades a lot less painful.
Changed
- Alpine AJAX is now bundled with the Alpine Morph plugin, so you can remove the Morph dependency from your project.
- The
x-ajax
attribute has been removed. Addx-target
to all links and forms that were previously nested under ax-ajax
element.x-noajax
can be removed completely. Also keep in mind that if you're using event listeners, you need to usex-init
orx-data
.
<!-- Before -->
<div x-ajax id="comments">
<form id="comment_form" x-target="comment_form" @ajax:success="doSomething()">
<input ...>
<button>Submit</button>
</form>
<a href="/comments?page=2">Page 2</a>
<a x-noajax href="/link">Link without AJAX</a>
</div>
<!-- After -->
<!-- Remove x-ajax -->
<div id="comments">
<!-- Add x-init on the form to handle the event listener -->
<form id="comment_form" x-target="comment_form" x-init @ajax:success="doSomething()">
<input ...>
<button>Submit</button>
</form>
<!-- Add x-target to make this link issue AJAX requests -->
<a href="/comments?page=2" x-target="comments">Page 2</a>
<!-- Remove `x-noajax`, links without x-target are just normal links -->
<a href="/link">Link without AJAX</a>
</div>
- The
x-load
attribute has been removed. Replace it withx-init
. - Incoming content is no longer inserted into the DOM using the Alpine Morph algorithm by default. The new default simply replaces the content without intelligently diffing the elements. This should be a low impact change, however in cases where you have Alpine component state you need to preserve across requests or if you're making updates to controls within a form, you may have broken functionality; In these cases you can restore the old default behavior by adding
x-arrange="morph"
to the targeted element. The toggle button pattern is an example of where you would needmorph
, so that keyboard focus is preserved on the button when the HTML is replaced:
<!-- Before -->
<form x-ajax id="star_repo" method="post" action="/repos/1/star">
<button>Toggle Button</button>
</form>
<!-- After -->
<form x-target id="star_repo" x-morph="arrange" method="post" action="/repos/1/star">
<button>Toggle Button</button>
</form>
Added
- New
x-arrange
attribute for arranging incoming content on the page. - New
x-focus
attribute for controlling keyboard focus. - New Infinite Scroll pattern example
v0.1.9
Added
- Pollyfilled
HTMLFormElement.requestSubmit()
v0.1.8
Added
- New mock server utility for building Alpine AJAX demos in environments like CodePen.
Fixed
- The fallback behavior for failed AJAX responses has been made more stable. Now, when an AJAX response returns a failed status code, and the response body does not contain a valid target element, links and forms will simply perform a standard navigation or form submission with AJAX behavior disabled.