Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/plugins/lazy-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ export const LazyLoadHintPlugin = createUnplugin(() => {
}
}

m.prepend(wrapperStatements + '\n')
const lastImport = imports[imports.length - 1]
// See https://github.com/nuxt/hints/issues/241
if (lastImport) {
m.appendRight(lastImport.end, '\n' + wrapperStatements)
}
else {
m.prepend(wrapperStatements + '\n')
}

if (m.hasChanged()) {
return {
Expand Down
12 changes: 6 additions & 6 deletions test/unit/hydration/lazy-hydration-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@
expect(result.code).toContain('useLazyComponentTracking(')
expect(result.code).toContain(`componentName: 'ChildComp'`)
expect(result.code).toMatchInlineSnapshot(`
"const ChildComp = __wrapImportedComponent(__original_ChildComp, 'ChildComp', './ChildComp.vue', '/src/Parent.ts')
import { __wrapImportedComponent, __wrapMainComponent } from "@nuxt/hints/runtime/lazy-load/composables";
import { useLazyComponentTracking } from "@nuxt/hints/runtime/lazy-load/composables";
"import { __wrapImportedComponent, __wrapMainComponent } from \"@nuxt/hints/runtime/lazy-load/composables\";

Check failure on line 182 in test/unit/hydration/lazy-hydration-plugin.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unnecessary escape character: \"

Check failure on line 182 in test/unit/hydration/lazy-hydration-plugin.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unnecessary escape character: \"
import { useLazyComponentTracking } from \"@nuxt/hints/runtime/lazy-load/composables\";

Check failure on line 183 in test/unit/hydration/lazy-hydration-plugin.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unnecessary escape character: \"

Check failure on line 183 in test/unit/hydration/lazy-hydration-plugin.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unnecessary escape character: \"
import { defineComponent } from 'vue'
import __original_ChildComp from './ChildComp.vue'
const ChildComp = __wrapImportedComponent(__original_ChildComp, 'ChildComp', './ChildComp.vue', '/src/Parent.ts')
export default defineComponent({
setup() {
const lazyHydrationState = useLazyComponentTracking([{ componentName: 'ChildComp', importSource: './ChildComp.vue', importedBy: '/src/Parent.ts', rendered: false }]);
Expand All @@ -207,11 +207,11 @@
const result = await transform(code, '/src/Parent.ts')
expect(result.code).toContain('useLazyComponentTracking(')
expect(result.code).toMatchInlineSnapshot(`
"const ChildComp = __wrapImportedComponent(__original_ChildComp, 'ChildComp', './ChildComp.vue', '/src/Parent.ts')
import { __wrapImportedComponent, __wrapMainComponent } from "@nuxt/hints/runtime/lazy-load/composables";
import { useLazyComponentTracking } from "@nuxt/hints/runtime/lazy-load/composables";
"import { __wrapImportedComponent, __wrapMainComponent } from \"@nuxt/hints/runtime/lazy-load/composables\";

Check failure on line 210 in test/unit/hydration/lazy-hydration-plugin.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unnecessary escape character: \"

Check failure on line 210 in test/unit/hydration/lazy-hydration-plugin.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unnecessary escape character: \"
import { useLazyComponentTracking } from \"@nuxt/hints/runtime/lazy-load/composables\";

Check failure on line 211 in test/unit/hydration/lazy-hydration-plugin.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unnecessary escape character: \"

Check failure on line 211 in test/unit/hydration/lazy-hydration-plugin.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unnecessary escape character: \"
import { defineComponent } from 'vue'
import __original_ChildComp from './ChildComp.vue'
const ChildComp = __wrapImportedComponent(__original_ChildComp, 'ChildComp', './ChildComp.vue', '/src/Parent.ts')
export default defineComponent({
setup: () => {
const lazyHydrationState = useLazyComponentTracking([{ componentName: 'ChildComp', importSource: './ChildComp.vue', importedBy: '/src/Parent.ts', rendered: false }]);
Expand Down
Loading