Skip to content

Commit 6ceb543

Browse files
s00dcursoragent
andcommitted
fix(vitepress): do not re-set routing on re-enhance
vue setRoutingStrategy targets last-installed app; calling it again from app1 after app2 install clobbers app2's adapter. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 76b6b8b commit 6ceb543

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

packages/vitepress/src/create.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ export function createVitePressI18n(options: VitePressI18nOptions): CreateVitePr
126126
state = { adapter, boundSyncHandler: null, chainedPrevious: undefined }
127127
byApp.set(app, state)
128128
}
129-
else {
130-
plugin.setRoutingStrategy(state.adapter)
131-
}
129+
// Re-enhance: do not call setRoutingStrategy — vue's setter targets last-installed
130+
// currentApp and would overwrite another app's router injection.
132131
lastAdapter = state.adapter
133132

134133
if (!syncWithVitePress) return

packages/vitepress/tests/with-i18n-micro.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,37 @@ describe('createVitePressI18n', () => {
310310
expect(app1.use).toHaveBeenCalledTimes(1)
311311
expect(app2.use).toHaveBeenCalledTimes(1)
312312
})
313+
314+
it('does not re-set routing strategy on re-enhance (avoids clobbering other apps)', () => {
315+
const { enhanceApp, plugin } = createVitePressI18n({
316+
locale: 'en',
317+
defaultLocale: 'en',
318+
locales: [{ code: 'en' }, { code: 'fr' }],
319+
messages: { en: { hi: 'Hi' }, fr: { hi: 'Salut' } },
320+
syncWithVitePress: false,
321+
})
322+
const setSpy = vi.spyOn(plugin, 'setRoutingStrategy')
323+
324+
const makeApp = () => ({
325+
use: vi.fn(),
326+
provide: vi.fn(),
327+
config: { globalProperties: {} as Record<string, unknown> },
328+
component: vi.fn(),
329+
})
330+
const makeRouter = (path: string) => ({
331+
route: { path },
332+
go: vi.fn(),
333+
onAfterRouteChange: undefined as ((to: string) => unknown) | undefined,
334+
})
335+
336+
const app1 = makeApp()
337+
const app2 = makeApp()
338+
enhanceApp({ app: app1 as never, router: makeRouter('/') as never })
339+
enhanceApp({ app: app2 as never, router: makeRouter('/fr/') as never })
340+
const afterTwo = setSpy.mock.calls.length
341+
expect(afterTwo).toBe(2)
342+
343+
enhanceApp({ app: app1 as never, router: makeRouter('/') as never })
344+
expect(setSpy.mock.calls.length).toBe(afterTwo)
345+
})
313346
})

0 commit comments

Comments
 (0)