The issue you're facing is related to the use of apostrophes in the content of the $slot variable. To fix this, you can escape the apostrophes in the content using the addslashes function in PHP. Here's an example of how you can modify the code to fix the issue:
@props(['limit' => 255, 'update_key' => 'dead'])
<!-- https://rappasoft.com/blog/building-a-constrained-textarea-using-alpinejs -->
<div
x-data="{
limit: {{ $limit }},
content: '{{ addslashes($slot) }}',
get remaining() {
return this.limit - this.content.length
}
}"
>
<textarea
x-model="content"
maxlength="{{ $limit }}"
{{ $attributes }}
>{{ $slot }}</textarea>
<p>
<small>You have <span x-text="remaining"></span> characters remaining.</small>
</p>
<button @click="$dispatch('spt', { key: '{{$update_key}}', content: content})" class="bg-blue-500 hover:bg-blue-700 text-white text-sm font-bold py-2 px-4 mb-2 rounded-full">
Save
</button>
</div>
By using the addslashes function, any apostrophes in the content will be properly escaped, preventing any issues with the JavaScript code.