# Vendored client assets

`livewire.js` is an esbuild bundle of the **official Livewire.js + Alpine.js core**
(collapse/focus/persist/intersect/sort/resize/anchor/morph/mask plugins) + nprogress, built
straight from [livewire/livewire](https://github.com/livewire/livewire)'s own `npm run build`.
It is **not authored in this repo** and must never be hand-edited — re-run the steps below
instead. `.prettierignore` excludes `assets/` for the same reason: the file must stay byte-for-byte
whatever upstream's build produces (never manually reformatted).

Currently vendored from upstream commit `ef269e57befc2add3ceb302dafbe14ff1bb526d4` (2026-08-10,
`main`), `dist/livewire.js` (non-CSP, unminified variant — matches this package's own separate
nonce-based CSP support instead of upstream's `livewire.csp.js` build).

The `_token` → `_csrf` string replace is applied at file-read time in
`providers/livewire_provider.ts` (`boot()`), never baked into the file on disk. The bundle also
contains one generated client patch: upstream's `js/events.js` `listen()` retains its DOM handler
and returns an unsubscribe function. This is required for `$wire.$on(...)` callers to remove
temporary listeners. It was built from the upstream source at the commit above; do not hand-edit
the generated bundle.

`livewire-styles.js` is a **small file we author ourselves** — it is NOT part of upstream
Livewire.js. It adds the client runtime for this port's `<style>`-scoping feature
(`src/features/support_styles`), which has no upstream equivalent because real Livewire scopes
`<style>` blocks at Blade-compile time, not at runtime. It only touches Livewire's public API
(`Livewire.hook(...)`, `component.addCleanup(...)`), so re-vendoring `livewire.js` never requires
touching it. It's served from its own `/livewire-styles.js` route and loaded via a second
`<script>` tag emitted by `@livewireScripts` — see `src/plugins/edge/tags.ts`.

## Updating the vendored bundle

```bash
git clone https://github.com/livewire/livewire.git /tmp/livewire-upstream
cd /tmp/livewire-upstream
npm install
node ./scripts/build.js
cp dist/livewire.js /path/to/adonisjs-livewire/packages/livewire/assets/livewire.js
```

When re-vendoring, reapply the `$wire.$on` patch to upstream `js/events.js` before building:

```js
export function listen(component, name, callback) {
  let handler = (e) => callback(e.detail)
  component.el.addEventListener(name, handler)
  return () => component.el.removeEventListener(name, handler)
}
```

Then:

1. Update the commit SHA / date noted above in this file.
2. Re-check `getNonce`/`data-livewire-style` support still exists upstream (grep the new bundle) —
   if upstream ever drops nonce support, `src/plugins/edge/tags.ts`'s nonce attributes stop doing
   anything client-side.
3. Re-check the `X-Livewire-Stream` wire-format assumptions in
   `providers/livewire_provider.ts` (`/livewire/update` handler) still match the new bundle's
   `extractStreamObjects()` regex (`{"stream":true,...,"endStream":true}`).
4. Run the full test suite (`npm run test`) — the vendored bundle backs
   `tests/features/csp/csp_nonce.spec.ts`, `tests/features/support_stream/streaming.spec.ts`, and
   `tests/features/support_styles/style_scoping.spec.ts` indirectly (they test the server side of
   each protocol, but a bundle regression would break the app-level integration these protect).
