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

useOffsetPagination attempted mutation of ref #3542

Closed
7 tasks done
VividLemon opened this issue Nov 12, 2023 · 5 comments · Fixed by #3581
Closed
7 tasks done

useOffsetPagination attempted mutation of ref #3542

VividLemon opened this issue Nov 12, 2023 · 5 comments · Fixed by #3581

Comments

@VividLemon
Copy link
Contributor

VividLemon commented Nov 12, 2023

Describe the bug

When using a value for pageSize or page in useOffsetPagination, it attempts to mutate the value

As shown in the playground instance, it runtime fails with Write operation failed: computed value is readonly (when the value is a computed, refs it will mutate directly

Reproduction

https://play.vueuse.org/#N4IgDghgxg1hDmBTAziAXAbVAOwgW0XRADcBXRAWgBNE8BLEAGhGQHtSAnKQtEU7MDHhMQNZFA50wAFzqtsRAGrkABABFadFQAoAFhAA2AMxV1sKgGIdE2KLoCUp5CogqaxRAdZgz8FaVkDOmkATxcDLwB3ZxD2FWlWFUjJaUQVAFVsOg8OZEMVZTSAGToAIw4ISRQVI1YOAtUAJhUAMhUAZhFOAyJdaWkwZDQAemH+QXgAOihWPGGyShp6YaDS4bMaAA9JvAArVABfRhx8HhAAAQXSZERh5H1rKhE2Tm4icaERMQkpWXkiADKD0QVAaiHSN38gWCdBQky6HB6vD6AyGow+Uxmc0u5Gut3ulRB5wAjAAGSbEyak9bYLY7fYgI4nAhEHGIPHDGbWZ7sLhnDFfFA-GRyBS8ADCrAiiCgf3MrBMKBu2Fk+UKKkleDArGQMPkGWhshQCKRIBRgxGYwEQmms2GbI5XMQJPJlOpG0Q2z2hwAuswjHQDMa0KAAIJgMCTBboUCpLUGCCpIgAHio2QAfAAdcwqVMZ7MqFTAYAQA4HAu54Zp4hZnN5msV4tgRAcAAKCEQZYrhe0eACiZBNQ4sxUpPiiWJKn1eHYKsH2jqKjYBCn0l0LZUQSMMpCUCD9nsFeTVfzdertcLxagnGsKvbSDLOj70gHzn1pQCCXMe7osEPdZPBs6w-fp9XOH9YAAXkzEBShg9NxSCWAVAIY8QK-C9K3PZ5hWkIg6C1OppCLfwbgAeSMIwbmke8zETUUVAOIcRwAcgdG5OTqRAWOzAjtQ4YjgGsIxGBULEwACEEmKMYc8BUFiFh47BsxmbBkGI4JaGcSCxNmCTUiobRtEcSD0xUDBiUYRpGHaRgABZGAAVkYAA2RgAHZGAADkYABOH1-xU+R1LEm8bBojsVB04TtGJf9VJC5s20i6LECMbRSUC2xguI1wdLxCiqMQCL4DouVtGACsEhfAw0B0EyzM0vBkCjQxyEmINsHgNdGArSAkABOgAC9EDqpL70QXqc360bQo4W8SsQbMDiyhLiNKKL6qiszKpzCBJmwT1pGM5bs0ZZhJTqNNcFSKNyBjEA4zABMk14esK1qFVoJAGdsFYGCK1KeBvqCeA+goRzSTHKhKhgNAYY4GAIahgGcyMINNm+gA-XSDFRwtUk2aRvu4OcOHxlQwG+xoKdKK6W2+4d+BoKhUcw5NkEgcxCeJmC7M2PGQHTYsVGINq0jLY9OYgbB2el7mju+5A5IRuHQfB3yobcWG0G8aBghCZGYJQ77pAoGmhYAWXYSERYTUpPEYg4pa52tj2w5hxEkGQiBoANDtbYdBgqit7c8OqAWkSQuqmwsxYMcg6oAOVIPAHY4KaVsZMsgA

System Info

System:
    OS: Linux 6.5 Pop!_OS 22.04 LTS
    CPU: (16) x64 AMD Ryzen 7 7800X3D 8-Core Processor
    Memory: 17.34 GB / 30.49 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.7.0 - /run/user/1000/fnm_multishells/160513_1699804871035/bin/node
    npm: 10.1.0 - /run/user/1000/fnm_multishells/160513_1699804871035/bin/npm
    pnpm: 8.6.5 - ~/.local/share/pnpm/pnpm
    bun: 1.0.2 - ~/.bun/bin/bun
  npmPackages:
    @vueuse/core: ^10.6.0 => 10.6.0 
    @vueuse/shared: ^10.5.0 => 10.5.0 
    vue: ^3.3.8 => 3.3.8

Used Package Manager

pnpm

Validations

@Doctor-wu
Copy link
Member

I didn't find any error in the playground you provided, and it seems to be intentional to mutate the pageSize according to the source code

@VividLemon
Copy link
Contributor Author

VividLemon commented Nov 17, 2023

An error happens when you have a computed value for pagesize

In addition, if the value is already the output value, (perPage is the original ref, and currentPageSize being the output) if the output already has the correct value, then perPage should not be mutated, just use currentPageSize. The only thing perPage should do is make a sync value, if it changes, currentPageSize should change.

@VividLemon
Copy link
Contributor Author

@VividLemon
Copy link
Contributor Author

Subsequently, if you are using a readonly value such as a computed, then the entire composable simply refuses to work, since the currentPage cannot get updated.

@Doctor-wu
Copy link
Member

It seems that it will indeed mutate page even if it's read-only, I'll commit a PR to fix it.

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 a pull request may close this issue.

2 participants