Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor defineLoader #246

Merged
merged 203 commits into from
Feb 21, 2024
Merged

Refactor defineLoader #246

merged 203 commits into from
Feb 21, 2024

Conversation

@posva posva force-pushed the refactor/create-define-loader branch from 9f2252b to d681268 Compare November 28, 2023 10:54
BREAKING CHANGE: since data loaders aren't meant to be awaited in script
setup (they are awaited at the navigation level), they now return a
promise of the raw data only, not of the UseDataLoaderReturn, to make it
clearer that this syntax is a bit special and should only be used within
nested loaders. This change also brings other benefits like allowing
lazy loaders to be awaited within loaders without changing their usage
outside, in components. Also, allowing different types of commit while
still allowing data to be awaited within loaders.
BREAKING CHANGE: While this was a private API, we are documenting it
here just in case. Replace `_defineBasicLoader` with `defineBasicLoader`
BREAKING CHANGE: The navigation guard is replaced in favor of a Vue
plugin:

Replace
```ts
import { setupLoaderGuard } from 'vue-router/auto'

setupLoaderGuard({ router, app })
```

with

```ts
import { DataLoaderPlugin } from 'vue-router/auto'

app.use(DataLoaderPlugin, { router })
```
@posva
Copy link
Owner Author

posva commented Feb 15, 2024

@SocketSecurity ignore npm/vue-demi@0.14.7

BREAKING CHANGE: Data Loaders have been redesigned to be more flexible
and account for other libraries. Notably, the caching behavior has been
moved out of the basic loader to an extended one and the basic loader
has no cache. All of the pending bugs have also been fixed.
I recommend you to give the RFC examples a new read to get
setup: https://uvr.esm.is/rfcs/data-loaders/. Most of the changes are
simplifying things by removing them.
Here is a list of the breaking changes to simplify
migration:

- The `dataFetching` option is no longer needed.
- Manual work needed to add loaders with `HasDataLoaderMeta` has been
  removed. It is just no longer needed. Loaders are picked up from lazy
  loaded components and must otherwise be directly added to a `meta.loaders`
  array. See the example at https://uvr.esm.is/rfcs/data-loaders/#basic-example
- The function `setupDataFetchingGuard` has been replaced with a Vue
  Plugin. See https://uvr.esm.is/rfcs/data-loaders/#data-loader-setup
  for details.
- If you were relying on `cacheTime`, use the `staleTime` option in the
  new [`defineColadaLoader()`](https://uvr.esm.is/rfcs/data-loaders/colada) based off [@pinia/colada](https://github.com/posva/pinia-colada)
- To reduce the dependency on file-based router, things have been
  refactored and none of the defineLoader functions are automatically
  imported anymore. You can add them yourself to the list of auto
  imports, or import them from `vue-router/auto`. The good news is you
  no longer need to use the plugin in order to benefit from the data
  loaders; they can be directly imported from
  `unplugin-vue-router/runtime`.

If you find missing information or improvements, please open a Pull
Request to improve the `CHANGELOG.md`.
Copy link

socket-security bot commented Feb 21, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@babel/types@7.23.9 environment +2 2.49 MB nicolo-ribaudo
npm/@pinia/colada@0.5.3 None 0 156 kB posva
npm/@rollup/pluginutils@5.1.0 None +3 223 kB shellscape
npm/@shikijs/vitepress-twoslash@1.1.6 environment +55 3.31 MB antfu
npm/@tanstack/vue-query@5.22.2 environment +3 2.86 MB tannerlinsley
npm/@types/node@20.11.19 None 0 4 MB types
npm/@vitest/coverage-v8@1.3.0 Transitive: environment, filesystem +22 6.68 MB antfu, oreanno, patak, ...1 more
npm/@vitest/ui@1.3.0 Transitive: environment, filesystem +23 2.44 MB vitestbot
npm/@vue-macros/common@1.10.1 filesystem Transitive: environment, eval, unsafe +27 10.5 MB sxzz
npm/@vue/compiler-sfc@3.4.19 environment, eval, filesystem, unsafe +15 9.17 MB yyx990803
npm/@vue/test-utils@2.4.4 eval Transitive: environment, filesystem, network, shell +22 5.81 MB lmiller1990
npm/@vue/tsconfig@0.5.1 None 0 10.6 kB soda
npm/chokidar@3.6.0 environment, filesystem +10 305 kB paulmillr
npm/fast-glob@3.3.2 filesystem +12 450 kB mrmlnc
npm/firebase@10.8.0 Transitive: environment, filesystem, network +60 116 MB google-wombot
npm/happy-dom@13.3.8 network, shell, unsafe +1 8.8 MB davidortner
npm/json-server@0.17.4 environment, filesystem Transitive: eval, network, unsafe +67 3.53 MB typicode
npm/lint-staged@15.2.2 Transitive: environment, filesystem, shell +28 1.24 MB okonet
npm/mande@2.0.8 environment, network 0 54.5 kB posva
npm/mlly@1.5.0 None +4 976 kB pi0
npm/nodemon@3.0.3 environment, filesystem, shell +19 645 kB remy
npm/nuxt@3.10.2 Transitive: environment, eval, filesystem, network, shell, unsafe +392 59.1 MB danielroe
npm/pathe@1.1.2 None 0 30.8 kB pi0
npm/pinia@2.1.7 environment +1 413 kB posva
npm/prettier@2.8.8 environment, filesystem, unsafe 0 11.2 MB prettier-bot

🚮 Removed packages: npm/@babel/core@7.21.8, npm/@babel/types@7.23.0, npm/@vitest/coverage-v8@0.34.6, npm/@vue/cli-plugin-router@5.0.8, npm/@vue/cli-plugin-typescript@5.0.8, npm/@vue/cli-service@5.0.8, npm/@vue/compiler-sfc@3.3.7, npm/@vue/test-utils@2.4.1, npm/@vue/tsconfig@0.4.0, npm/chokidar@3.5.3, npm/esno@4.0.0, npm/fast-glob@3.3.1, npm/happy-dom@12.10.3, npm/lint-staged@15.1.0, npm/mlly@1.4.2, npm/nodemon@3.0.2, npm/nuxt@3.5.0, npm/pathe@1.1.1

View full report↗︎

BREAKING CHANGE: Remove the deprecated APIs:
- `createPrefixTree()` -> `new PrefixTree()`
- `VueRouterExports` -> `VueRouterAutoImports`
@posva posva merged commit 15aa3d1 into main Feb 21, 2024
10 checks passed
@posva posva deleted the refactor/create-define-loader branch February 21, 2024 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment