Skip to content

refactor(vue3): build CollectionView on nativescript-vue's useItemTemplates - #105

Merged
farfromrefug merged 3 commits into
nativescript-community:masterfrom
rigor789:fix/vue3-forwarded-slots
Sep 19, 2026
Merged

farfromrefug merged 3 commits into
nativescript-community:masterfrom
rigor789:fix/vue3-forwarded-slots

Conversation

@rigor789

@rigor789 rigor789 commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Follow-up to the discussion below: the cell machinery now lives in nativescript-vue as useItemTemplates() (nativescript-vue#1170), shared with the built-in ListView, so this PR swaps the Vue 3 component onto it instead of copying the Fragment-unwrapping fix here. Two commits, reviewable separately:

refactor(vue3): build CollectionView on useItemTemplates. Cells become keyed children of the component's own tree (the native element is registered with NO_CHILDREN, so Vue patches them but the native view places them) instead of being rendered into private roots with a hand-copied appContext. That fixes:

  • templates forwarded through a slot (rendered as a Fragment) crashing on the first itemLoading, the original subject of this PR
  • inject() inside a cell not seeing values provided by the surrounding page component
  • components inside cells never being unmounted; itemDisposing now unmounts the cell

The _batchUpdate wrapper around cell updates is kept. alias / itemIdGenerator and the (item, index, items) selector signature are unchanged.

fix(vue3): refresh on in-place array mutations. The items watcher declared its arguments as (oldVal, newVal) while Vue passes the new value first, so it type-checked the new array and pushed the old one to the native view. Replacing the array is already handled by the render; the watcher now refreshes the native view when a plain array is mutated in place, and leaves ObservableArray alone since it notifies the view itself.

Requires nativescript-vue >= 3.1.2. master's lockfile and demo-vue3 already resolve it, but the recorded tools commit still pins nativescript-vue3 to 3.0.1, so the last commit moves that pointer to the plugin-seed-tools#4 merge. If the submodule update action lands the same pointer first, that commit becomes a no-op and can be dropped. The Vue 3 sources type-check against the published 3.1.2; not run on device from this branch. tsc does report one error in index-common.ts (Builder.parseMultipleTemplates now takes two arguments in @nativescript/core 9.0.20), which is already on master and unrelated to this PR.

@farfromrefug

Copy link
Copy Markdown
Member

@rigor789 thanks Igor for this PR. but i wonder about the PR description. was this tested? you are saying this patched was applied the same way on the vue3 ListView component and it worked?

@rigor789

Copy link
Copy Markdown
Member Author

I tested with this change locally on ListView: nativescript-vue/nativescript-vue@feb5b37

And yes that fixed it, however I do wonder if perhaps this should be a utility exported from nativescript-vue, what do you think?

@farfromrefug

Copy link
Copy Markdown
Member

@rigor789 yes if we already use it in both ListView/CollectionView. And we might add it to ui-pager for example

@rigor789
rigor789 force-pushed the fix/vue3-forwarded-slots branch from 4f85878 to 8cf62f5 Compare September 15, 2026 07:36
@rigor789 rigor789 changed the title fix(vue3): accept templates forwarded through a slot refactor(vue3): build CollectionView on nativescript-vue's useItemTemplates Sep 15, 2026
@rigor789

Copy link
Copy Markdown
Member Author

@farfromrefug done: nativescript-vue/nativescript-vue#1170 adds useItemTemplates() (plus templateRoots and createItemContext), ListView is built on it there, and this PR now swaps CollectionView onto it. Second commit fixes the swapped (oldVal, newVal) in the items watcher I noticed while in there. A ui-pager Vue 3 component on the same composable is coming as a separate PR.

…plates

The cell machinery now lives in nativescript-vue (useItemTemplates,
nativescript-vue/nativescript-vue#1170) and is shared with ListView.
Cells become part of the component's own tree instead of being rendered
into private roots, which fixes:

- templates forwarded through a slot (rendered as a Fragment) crashing
  on the first itemLoading
- inject() inside a cell not seeing values provided by the surrounding
  component
- components inside cells never being unmounted when the native view
  disposes them

Requires nativescript-vue >= 3.2.0.
The items watcher declared its arguments as (oldVal, newVal) while Vue
passes the new value first, so it type-checked the new array and pushed
the old one to the native view. Replacing the array is already handled
by the render, so the watcher only needs to refresh the native view when
a plain array is mutated in place; ObservableArray notifies it itself.
The lockfile already resolves nativescript-vue3 to 3.1.2, but the
recorded tools commit still pins 3.0.1, so a fresh checkout resolves the
old version and the Vue 3 component does not build.
@rigor789
rigor789 force-pushed the fix/vue3-forwarded-slots branch from 4751a9d to 1d534be Compare September 19, 2026 08:35
@farfromrefug
farfromrefug merged commit 60466a2 into nativescript-community:master Sep 19, 2026
@farfromrefug

Copy link
Copy Markdown
Member

@rigor789 thanks Igor!

@rigor789
rigor789 deleted the fix/vue3-forwarded-slots branch September 20, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants