diff --git a/CHANGELOG.md b/CHANGELOG.md index fa72ed8..92e55f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ No unreleased changes. +## 0.9.3 + +- fix: remove head objects at right index + ## 0.9.2 - chore: bump zhead schema diff --git a/package.json b/package.json index 0d8dd50..7bf9bc0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vueuse/head", - "version": "0.9.2", + "version": "0.9.3", "packageManager": "pnpm@7.5.0", "description": "Document head manager for Vue 3. SSR ready.", "author": { diff --git a/src/index.ts b/src/index.ts index 0b2d046..2d60785 100644 --- a/src/index.ts +++ b/src/index.ts @@ -218,7 +218,8 @@ export const createHead = (initHeadObject?: UseHeadInp addHeadObjs(objs, options?) { const ctx = allHeadObjs.push({ input: objs, options }) return () => { - allHeadObjs = allHeadObjs.splice(ctx, 1) + // remove ctx + allHeadObjs.splice(ctx - 1, 1) } }, diff --git a/tests/basic.test.ts b/tests/basic.test.ts new file mode 100644 index 0000000..36609ea --- /dev/null +++ b/tests/basic.test.ts @@ -0,0 +1,42 @@ +import { createHead } from '../src' + +describe('basic', () => { + test('removing head works', async () => { + const head = createHead() + head.addHeadObjs( + () => ({ + title: 'old', + link: [ + { + href: '/', + }, + ], + }), + ) + const rm = head.addHeadObjs( + () => ({ + title: 'test', + }), + ) + rm() + + expect(head.headTags).toMatchInlineSnapshot(` + [ + { + "_position": 0, + "props": { + "textContent": "old", + }, + "tag": "title", + }, + { + "_position": 1, + "props": { + "href": "/", + }, + "tag": "link", + }, + ] + `) + }) +})