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

fix(types)(middleware/devtools): avoid copying types #1991

Merged
merged 8 commits into from
Oct 2, 2023

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Aug 12, 2023

Related Issues or Discussions

follow-up #1207

Summary

We found a better solution in pmndrs/valtio#777

Check List

  • yarn run prettier for formatting code and docs

@vercel
Copy link

vercel bot commented Aug 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zustand-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 29, 2023 1:14pm

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 12, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit e486530:

Sandbox Source
React Configuration
React TypeScript Configuration
React Browserify Configuration
React Snowpack Configuration
React Parcel Configuration
Next.js Configuration
@pavlobu/zustand demo Configuration

@github-actions
Copy link

github-actions bot commented Aug 12, 2023

Size Change: -1 B (0%)

Total Size: 43.5 kB

Filename Size Change
dist/system/middleware.production.js 2.62 kB -1 B (0%)
ℹ️ View Unchanged
Filename Size
dist/context.js 782 B
dist/esm/context.js 590 B
dist/esm/index.js 706 B
dist/esm/middleware.js 3.87 kB
dist/esm/middleware/immer.js 210 B
dist/esm/shallow.js 509 B
dist/esm/traditional.js 392 B
dist/esm/vanilla.js 629 B
dist/index.js 868 B
dist/middleware.js 4.43 kB
dist/middleware/immer.js 328 B
dist/shallow.js 1.11 kB
dist/system/context.development.js 697 B
dist/system/context.production.js 386 B
dist/system/index.development.js 873 B
dist/system/index.production.js 402 B
dist/system/middleware.development.js 4 kB
dist/system/middleware/immer.development.js 292 B
dist/system/middleware/immer.production.js 187 B
dist/system/shallow.development.js 558 B
dist/system/shallow.production.js 344 B
dist/system/traditional.development.js 505 B
dist/system/traditional.production.js 342 B
dist/system/vanilla.development.js 672 B
dist/system/vanilla.production.js 310 B
dist/traditional.js 433 B
dist/umd/context.development.js 887 B
dist/umd/context.production.js 556 B
dist/umd/index.development.js 999 B
dist/umd/index.production.js 543 B
dist/umd/middleware.development.js 4.58 kB
dist/umd/middleware.production.js 2.97 kB
dist/umd/middleware/immer.development.js 482 B
dist/umd/middleware/immer.production.js 342 B
dist/umd/shallow.development.js 1.23 kB
dist/umd/shallow.production.js 883 B
dist/umd/traditional.development.js 613 B
dist/umd/traditional.production.js 447 B
dist/umd/vanilla.development.js 800 B
dist/umd/vanilla.production.js 410 B
dist/vanilla.js 683 B

compressed-size-action

docs/recipes/recipes.mdx Outdated Show resolved Hide resolved
@dai-shi dai-shi added this to the v4.4.2 milestone Oct 2, 2023
@dai-shi dai-shi merged commit 8b242ce into main Oct 2, 2023
33 checks passed
@dai-shi dai-shi deleted the fix/improve-devtools-typing branch October 2, 2023 12:58
@birtles
Copy link

birtles commented Oct 3, 2023

@dai-shi What's the upgrade path here for going from 4.4.1 to 4.4.2? I've manually added @redux-devtools/extension but it doesn't seem to help.

For the following code:

  const store = useReduxDevTools
    ? createStore(
        devtools(stateCreator, {
          enabled: true,
          name: 'app',
          serialize: {
            options: {
              symbol: true,
            },
            replacer: (_key, value) => {
              // ...
          },
        })
      )
    : createStore(stateCreator);

after updating to 4.4.2 I get:

ERROR in /home/birtles/project/src/app/store.ts
./src/app/store.ts 74:10-19
[tsl] ERROR in /home/project/src/app/store.ts(74,11)
      TS2345: Argument of type '{ enabled: true; name: string; serialize: { options: { symbol: boolean; }; replacer: (_key: any, value: any) => any; }; }' is not assignable to parameter of type 'DevtoolsOptions'.
  Object literal may only specify known properties, and 'serialize' does not exist in type 'DevtoolsOptions'.
 @ ./src/app/dispatch.ts 9:0-39 11:11-22
 @ ./src/i18n/provider.tsx 5:0-43 70:8-16
 @ ./src/index.tsx 15:0-47 18:12-24

According to pmndrs/valtio#777 (comment), however, installing @redux-devtools/extension should be enough to ensure __REDUX_DEVTOOLS_EXTENSION__ is declared (which would presumably cause DevtoolsOptions to be defined correctly?)

Is there something else I need to do here?

@dai-shi
Copy link
Member Author

dai-shi commented Oct 3, 2023

Thanks for reporting.
Sorry, I should have written the migration guide in the release note.
We need to add this line in the app code explicitly:
https://github.com/pmndrs/zustand/pull/1991/files#diff-5a831ea67cf5cf8703b0de46901ab25bd191f56b320053be9332d9a3b0d01d15R498

@birtles
Copy link

birtles commented Oct 3, 2023

Perfect! Thank you!

@razzeee
Copy link

razzeee commented Oct 4, 2023

I guess we also need to add @redux-devtools/extension to our package.json? As that isn't mentioned in the readme yet?

@dai-shi
Copy link
Member Author

dai-shi commented Oct 4, 2023

It doesn't appear after the build. Yeah, only one line is added in readme.
Our rule is the readme is intentionally for JavaScript, so we should write detailed instruction in ./docs. Feel free to help improving it.
BTW, this gives me an idea to mitigate it. We can infer to any if the type isn't found. I think it makes more sense in this specific case.

@dai-shi
Copy link
Member Author

dai-shi commented Oct 4, 2023

#2099

Hope if someone can try it: https://ci.codesandbox.io/status/pmndrs/zustand/pr/2099 (Find "Local Install Instructions")

bodinsamuel referenced this pull request in specfy/specfy Nov 8, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [zustand](https://togithub.com/pmndrs/zustand) | [`4.4.1` ->
`4.4.6`](https://renovatebot.com/diffs/npm/zustand/4.4.1/4.4.6) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/zustand/4.4.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/zustand/4.4.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/zustand/4.4.1/4.4.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/zustand/4.4.1/4.4.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>pmndrs/zustand (zustand)</summary>

### [`v4.4.6`](https://togithub.com/pmndrs/zustand/releases/tag/v4.4.6)

[Compare
Source](https://togithub.com/pmndrs/zustand/compare/v4.4.5...v4.4.6)

v4.4.5 has an issue with some TypeScript configs about module
resolution. It should be fixed now. Thanks for the patience.

#### What's Changed

- Update export types by
[@&#8203;dbritto-dev](https://togithub.com/dbritto-dev) in
[https://github.com/pmndrs/zustand/pull/2170](https://togithub.com/pmndrs/zustand/pull/2170)

#### New Contributors

- [@&#8203;cheatkey](https://togithub.com/cheatkey) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/2147](https://togithub.com/pmndrs/zustand/pull/2147)
- [@&#8203;frixaco](https://togithub.com/frixaco) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/2166](https://togithub.com/pmndrs/zustand/pull/2166)

**Full Changelog**:
pmndrs/zustand@v4.4.5...v4.4.6

### [`v4.4.5`](https://togithub.com/pmndrs/zustand/releases/tag/v4.4.5)

[Compare
Source](https://togithub.com/pmndrs/zustand/compare/v4.4.4...v4.4.5)

Hopefully, it should fix some issues with Node.js environment including
Next.js.

#### What's Changed

- fix: importing CJS React in ESM by
[@&#8203;dai-shi](https://togithub.com/dai-shi) in
[https://github.com/pmndrs/zustand/pull/2154](https://togithub.com/pmndrs/zustand/pull/2154)
- Apply publint recommendations by
[@&#8203;dbritto-dev](https://togithub.com/dbritto-dev) in
[https://github.com/pmndrs/zustand/pull/2157](https://togithub.com/pmndrs/zustand/pull/2157)

#### New Contributors

- [@&#8203;plrs9816](https://togithub.com/plrs9816) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/2137](https://togithub.com/pmndrs/zustand/pull/2137)
- [@&#8203;Brammm](https://togithub.com/Brammm) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/2139](https://togithub.com/pmndrs/zustand/pull/2139)
- [@&#8203;sobies93](https://togithub.com/sobies93) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/2142](https://togithub.com/pmndrs/zustand/pull/2142)

**Full Changelog**:
pmndrs/zustand@v4.4.4...v4.4.5

### [`v4.4.4`](https://togithub.com/pmndrs/zustand/releases/tag/v4.4.4)

[Compare
Source](https://togithub.com/pmndrs/zustand/compare/v4.4.3...v4.4.4)

There was a tiny issue in v4.4.3, which broke with some bundlers, which
this version fixes.

#### What's Changed

- fix(build): patch entry points zustand/shallow for CJS by
[@&#8203;dai-shi](https://togithub.com/dai-shi) in
[https://github.com/pmndrs/zustand/pull/2128](https://togithub.com/pmndrs/zustand/pull/2128)

**Full Changelog**:
pmndrs/zustand@v4.4.3...v4.4.4

### [`v4.4.3`](https://togithub.com/pmndrs/zustand/releases/tag/v4.4.3)

[Compare
Source](https://togithub.com/pmndrs/zustand/compare/v4.4.2...v4.4.3)

The changes in v4.4.2 were troublesome for some users. This version
should fix/mitigate such cases.

#### What's Changed

- fix(shallow): Extract shallow vanilla and react by
[@&#8203;dbritto-dev](https://togithub.com/dbritto-dev) in
[https://github.com/pmndrs/zustand/pull/2097](https://togithub.com/pmndrs/zustand/pull/2097)
- fix(types): mitigate devtools typing by
[@&#8203;dai-shi](https://togithub.com/dai-shi) in
[https://github.com/pmndrs/zustand/pull/2099](https://togithub.com/pmndrs/zustand/pull/2099)

**Full Changelog**:
pmndrs/zustand@v4.4.2...v4.4.3

### [`v4.4.2`](https://togithub.com/pmndrs/zustand/releases/tag/v4.4.2)

[Compare
Source](https://togithub.com/pmndrs/zustand/compare/v4.4.1...v4.4.2)

This adds `useShallow` hook to cover some use cases that are deprecated
with v4.4.0 change. Check out [the
guide](https://togithub.com/pmndrs/zustand/blob/ec538e9d4c0b9b5759e6dfd0fd3c9a21f8236949/docs/guides/prevent-rerenders-with-use-shallow.md).

##### Migration Guide

[#&#8203;1991](https://togithub.com/pmndrs/zustand/issues/1991) requires
something like below if you are using the `devtools` middleware *and*
TypeScript.

```diff
  import { devtools } from 'zustand/middleware'
+ import type {} from '@&#8203;redux-devtools/extension'
```

##### What's Changed

- fix(types)(middleware/devtools): avoid copying types by
[@&#8203;dai-shi](https://togithub.com/dai-shi) in
[https://github.com/pmndrs/zustand/pull/1991](https://togithub.com/pmndrs/zustand/pull/1991)
- fix(traditional): make defaultEqualityFn optional in TS Types by
[@&#8203;charkour](https://togithub.com/charkour) in
[https://github.com/pmndrs/zustand/pull/2060](https://togithub.com/pmndrs/zustand/pull/2060)
- feat: add useShallow by
[@&#8203;FaberVitale](https://togithub.com/FaberVitale) in
[https://github.com/pmndrs/zustand/pull/2090](https://togithub.com/pmndrs/zustand/pull/2090)

##### New Contributors

- [@&#8203;aykutkardas](https://togithub.com/aykutkardas) made their
first contribution in
[https://github.com/pmndrs/zustand/pull/1993](https://togithub.com/pmndrs/zustand/pull/1993)
- [@&#8203;michelts](https://togithub.com/michelts) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/1997](https://togithub.com/pmndrs/zustand/pull/1997)
- [@&#8203;elusive](https://togithub.com/elusive) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/2001](https://togithub.com/pmndrs/zustand/pull/2001)
- [@&#8203;mayank1513](https://togithub.com/mayank1513) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/2015](https://togithub.com/pmndrs/zustand/pull/2015)
- [@&#8203;fdb](https://togithub.com/fdb) made their first contribution
in
[https://github.com/pmndrs/zustand/pull/2029](https://togithub.com/pmndrs/zustand/pull/2029)
- [@&#8203;tmkx](https://togithub.com/tmkx) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/2032](https://togithub.com/pmndrs/zustand/pull/2032)
- [@&#8203;OshriAsulin](https://togithub.com/OshriAsulin) made their
first contribution in
[https://github.com/pmndrs/zustand/pull/2028](https://togithub.com/pmndrs/zustand/pull/2028)
- [@&#8203;ivanquirino](https://togithub.com/ivanquirino) made their
first contribution in
[https://github.com/pmndrs/zustand/pull/2047](https://togithub.com/pmndrs/zustand/pull/2047)
- [@&#8203;stavkamil](https://togithub.com/stavkamil) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/2071](https://togithub.com/pmndrs/zustand/pull/2071)
- [@&#8203;NaamuKim](https://togithub.com/NaamuKim) made their first
contribution in
[https://github.com/pmndrs/zustand/pull/2088](https://togithub.com/pmndrs/zustand/pull/2088)
- [@&#8203;FaberVitale](https://togithub.com/FaberVitale) made their
first contribution in
[https://github.com/pmndrs/zustand/pull/2090](https://togithub.com/pmndrs/zustand/pull/2090)

**Full Changelog**:
pmndrs/zustand@v4.4.1...v4.4.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 4pm every weekday" in timezone
Europe/Paris, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/specfy/specfy).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6ImNob3JlL3Jlbm92YXRlQmFzZUJyYW5jaCJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

5 participants