Repository navigation
x-for and x-sort not working in FiveM CEF browser #4847
Replies: 2 comments 3 replies
|
There are two different things to separate here: DOM sorting and Alpine state sorting.
Give every sortable item a stable sort key and update the array in the <div
x-data="{
items: [],
move(slot, position) {
const from = this.items.findIndex(item => item.slot === slot)
if (from === -1 || from === position) return
const [item] = this.items.splice(from, 1)
this.items.splice(position, 0, item)
}
}"
>
<div
x-sort="move($item, $position)"
x-sort:group="inventory"
x-sort:config="{ forceFallback: true, fallbackOnBody: true }"
>
<template x-for="item in items" :key="item.slot">
<div x-sort:item="item.slot">
<!-- item.label / item.weight / item.model -->
</div>
</template>
</div>
</div>The important changes are:
If this still fails in FiveM CEF, I would reduce it to a plain SortableJS reproduction with the same |
|
My guess is something is causing the whole x-for to basically reload, so some are getting disconnected from the state and there are expressions not being directed properly. The errors you're seeing would then be unrelated to any incorrect results you're getting, aside from helping you see that there is an issue. Those expression errors should only happen if that element gets disconnected from the dom and the expression effect not being unqueued, which would suggest something else is disconnecting the elements outside of the Alpine lifecycle Oh, looking at your video, yeah, the error you're seeing is from your DnD "clone" of the element having the expressions but not actually being in an alpine scope. You might be able to solve it by whatever your dnd thing is making the clone stripping out alpine expressions, adding something like "x-ignore" on it, or by explicitely using |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Alpine.js version
v3.15.12
Browser and operating system
Chromium Embedded Framework (CEF)
What do you need help with?
I’m working with FiveM NUI, which uses a CEF-based browser with the following user agent:
Issue
The combination of
x-forandx-sortfrom Alpine.js works correctly in modern browsers but fails inside the FiveM CEF environment.x-fordoes not update properly when a drag operation occurs. The dragging functionality is not working.Example
Screenshots


How do you expect it to work?
The
x-sortdragging functionality should work smoothly and consistently inside the FiveM CEF browser, allowing users to drag and reorder items without glitches or interruptions.Please confirm
All reactions