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: Attempt to update for projects using moduleResolution="bundler" by downgrading react-select #284

Merged
merged 14 commits into from
Oct 4, 2023

Conversation

csandman
Copy link
Owner

@csandman csandman commented Sep 29, 2023

This PR fixes the type issues people have been experiencing with all of the custom types included in this package. This issue was initially caused by upgrading the react-select dependency to v5.7.1, in which the exports field was added to their package.json. This is a relatively newer alternative to the main and module fields of the package.json in which people can define the paths at which different package parts can be imported by other packages. The problematic difference between this and the legacy fields, is that if a project finds the package paths using this exports field, it is limited to importing the files that are included in that exports field, and if a file is not included, it's impossible to access from the parent project. That is, as far as I'm aware, the whole node ecosystem is so fragmented and hard to keep track of so I'm not entirely sure about any of this, it's just what I've seen in practice.

The problem here is that this package uses module augmentation to add extra props to the root select component that are specific to Chakra, like size, variant, and chakraStyles. This was done using the recommended approach from the react-select docs, however when they added the new exports field, they did not account for the fact that they also had to include an export for these types in order for the module augmentation to still be possible.

It took me a while to discover why this was only happening for some people and not others, but eventually I realized it was due to the moduleResolution setting in the tsconfig.json file. If this property is set to bundler, node16, or nodenext, that triggers the project to look for the exports field in the package.json of dependencies (and nested dependencies apparently) which breaks the module augmentation in this package.

This is a very simple fix for the react-select team, as all they have to do is add the type declaration files to their exports field and everything should work totally fine. I actually made a PR to their repo with a fix (JedWatson/react-select#5762), but their approval process can be kind of slow. If you'd like to help it along, interacting with that PR with a reaction or comment could help them to notice it.

Considering the module augmentation is very fundamental to making this package work, I have decided that the best alternative is simply to downgrade this package's react-select version to v5.7.0, the version directly before the one that included the breaking change, until my PR or another fix is merged/published. Since that version, they have only had a few patch releases with nothing super important changing, so as long as my PR get's merged at some point, I'd rather stick to their older version for now.

If this issue is not something that has affected you, and you'd like to continue using the latest version of react-select, you can always override this dependency version by using the overrides field in the package.json:

  "chakra-react-select": {
      "react-select": "^5.7.7"
    }

And as soon as a fix is published for react-select, I will be upgrade the dependency to their newest version.


Here are some related links:

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 29, 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 8337ea2:

Sandbox Source
chakra-react-select demo Configuration
chakra-react-select TS demo Configuration
chakra-react-select + next.js Configuration
chakra-react-select + next.js + typescript Configuration

@github-actions
Copy link

github-actions bot commented Sep 29, 2023

📊 Package size report   -3.11%↓

File Before After
dist/cjs/chakra-components/containers.js 4.1 kB -1.32%↓4.0 kB
dist/cjs/chakra-components/containers.js.map 8.2 kB -0.43%↓8.1 kB
dist/cjs/chakra-components/control.js 10.4 kB -1.03%↓10.3 kB
dist/cjs/chakra-components/control.js.map 19.2 kB -0.42%↓19.1 kB
dist/cjs/chakra-components/index.js 2.8 kB -0.36%↓2.7 kB
dist/cjs/chakra-components/index.js.map 3.8 kB -0.31%↓3.8 kB
dist/cjs/chakra-components/input.js 3.5 kB -0.29%↓3.5 kB
dist/cjs/chakra-components/input.js.map 6.5 kB -0.18%↓6.5 kB
dist/cjs/chakra-components/menu.js 11.8 kB -0.71%↓11.7 kB
dist/cjs/chakra-components/menu.js.map 22.9 kB -0.33%↓22.8 kB
dist/cjs/chakra-components/multi-value.js 6.4 kB -1.03%↓6.3 kB
dist/cjs/chakra-components/multi-value.js.map 13.1 kB -0.36%↓13.1 kB
dist/cjs/chakra-components/placeholder.js 1.4 kB -0.73%↓1.4 kB
dist/cjs/chakra-components/placeholder.js.map 2.8 kB -0.43%↓2.8 kB
dist/cjs/chakra-components/single-value.js 1.5 kB -0.67%↓1.5 kB
dist/cjs/chakra-components/single-value.js.map 3.0 kB -0.39%↓3.0 kB
dist/cjs/select/async-creatable-select.js 2.3 kB -0.43%↓2.3 kB
dist/cjs/select/async-creatable-select.js.map 3.8 kB -0.29%↓3.8 kB
dist/cjs/select/async-select.js 2.2 kB -0.45%↓2.2 kB
dist/cjs/select/async-select.js.map 3.6 kB -0.3%↓3.6 kB
dist/cjs/select/creatable-select.js 2.3 kB -0.44%↓2.3 kB
dist/cjs/select/creatable-select.js.map 3.7 kB -0.3%↓3.7 kB
dist/cjs/select/select.js 2.2 kB -0.45%↓2.2 kB
dist/cjs/select/select.js.map 3.5 kB -0.31%↓3.5 kB
dist/cjs/use-chakra-select-props.js 5.0 kB -0.2%↓5.0 kB
dist/cjs/use-chakra-select-props.js.map 7.9 kB -0.15%↓7.9 kB
dist/cjs/utils.js 3.1 kB -0.87%↓3.1 kB
dist/cjs/utils.js.map 5.6 kB -0.41%↓5.6 kB
dist/types/chakra-components/containers.d.ts 717 B -0.14%↓716 B
dist/types/chakra-components/containers.d.ts.map 352 B
dist/types/chakra-components/control.d.ts 1.7 kB 5%↑1.8 kB
dist/types/chakra-components/control.d.ts.map 619 B
dist/types/chakra-components/index.d.ts 5.5 kB 4%↑5.7 kB
dist/types/chakra-components/index.d.ts.map 208 B
dist/types/chakra-components/input.d.ts 296 B -13.5%↓256 B
dist/types/chakra-components/input.d.ts.map 267 B
dist/types/chakra-components/menu.d.ts 1.4 kB 7%↑1.5 kB
dist/types/chakra-components/menu.d.ts.map 520 B
dist/types/chakra-components/multi-value.d.ts 1.1 kB 2%↑1.2 kB
dist/types/chakra-components/multi-value.d.ts.map 463 B
dist/types/chakra-components/placeholder.d.ts 326 B -14.1%↓280 B
dist/types/chakra-components/placeholder.d.ts.map 282 B
dist/types/chakra-components/single-value.d.ts 327 B -14.4%↓280 B
dist/types/chakra-components/single-value.d.ts.map 284 B
dist/types/index.d.ts 1.2 kB -2.87%↓1.2 kB
dist/types/index.d.ts.map 975 B
dist/types/module-augmentation.d.ts 10.5 kB -0.47%↓10.4 kB
dist/types/module-augmentation.d.ts.map 2.2 kB
dist/types/select/async-creatable-select.d.ts 624 B -8.33%↓572 B
dist/types/select/async-creatable-select.d.ts.map 646 B
dist/types/select/async-select.d.ts 550 B -7.64%↓508 B
dist/types/select/async-select.d.ts.map 618 B
dist/types/select/creatable-select.d.ts 582 B -7.9%↓536 B
dist/types/select/creatable-select.d.ts.map 626 B
dist/types/select/select.d.ts 472 B -7.63%↓436 B
dist/types/select/select.d.ts.map 566 B
dist/types/types.d.ts 3.5 kB -1.01%↓3.4 kB
dist/types/types.d.ts.map 3.4 kB
dist/types/use-chakra-select-props.d.ts 617 B -8.59%↓564 B
dist/types/use-chakra-select-props.d.ts.map 255 B
dist/types/utils.d.ts 746 B -4.69%↓711 B
dist/types/utils.d.ts.map 328 B
package.json 4.0 kB 0.05%↑4.0 kB
Total (Includes all files) 433.9 kB -3.11%↓420.4 kB
Tarball size 73.8 kB -4.85%↓70.2 kB
Unchanged files
File Size
dist/cjs/index.js 2.0 kB
dist/cjs/index.js.map 2.9 kB
dist/cjs/module-augmentation.js 61 B
dist/cjs/module-augmentation.js.map 10.3 kB
dist/cjs/types.js 47 B
dist/cjs/types.js.map 3.7 kB
dist/esm/chakra-components/containers.js 3.6 kB
dist/esm/chakra-components/containers.js.map 7.4 kB
dist/esm/chakra-components/control.js 9.6 kB
dist/esm/chakra-components/control.js.map 17.8 kB
dist/esm/chakra-components/index.js 1.3 kB
dist/esm/chakra-components/index.js.map 2.5 kB
dist/esm/chakra-components/input.js 3.2 kB
dist/esm/chakra-components/input.js.map 5.4 kB
dist/esm/chakra-components/menu.js 10.9 kB
dist/esm/chakra-components/menu.js.map 21.9 kB
dist/esm/chakra-components/multi-value.js 5.9 kB
dist/esm/chakra-components/multi-value.js.map 12.3 kB
dist/esm/chakra-components/placeholder.js 1.1 kB
dist/esm/chakra-components/placeholder.js.map 2.1 kB
dist/esm/chakra-components/single-value.js 1.2 kB
dist/esm/chakra-components/single-value.js.map 2.3 kB
dist/esm/index.js 687 B
dist/esm/index.js.map 1.9 kB
dist/esm/module-augmentation.js 58 B
dist/esm/module-augmentation.js.map 10.3 kB
dist/esm/select/async-creatable-select.js 856 B
dist/esm/select/async-creatable-select.js.map 1.9 kB
dist/esm/select/async-select.js 800 B
dist/esm/select/async-select.js.map 1.8 kB
dist/esm/select/creatable-select.js 824 B
dist/esm/select/creatable-select.js.map 1.9 kB
dist/esm/select/select.js 768 B
dist/esm/select/select.js.map 1.7 kB
dist/esm/types.js 44 B
dist/esm/types.js.map 3.7 kB
dist/esm/use-chakra-select-props.js 4.7 kB
dist/esm/use-chakra-select-props.js.map 6.8 kB
dist/esm/utils.js 2.9 kB
dist/esm/utils.js.map 4.7 kB
LICENSE.md 1.1 kB
README.md 45.9 kB

🤖 This report was automatically generated by pkg-size-action

@csandman csandman closed this Oct 2, 2023
@csandman csandman reopened this Oct 3, 2023
@csandman csandman changed the title fix: Attempt to update to moduleResolution="bundler" and patch react-select fix: Attempt to update for projects using moduleResolution="bundler" by downgrading react-select Oct 3, 2023
@csandman csandman merged commit 654a643 into main Oct 4, 2023
3 checks passed
@csandman csandman deleted the fix/patch-react-select branch October 4, 2023 18:19
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.

Property "size" does not exist on type [BUG] selectedOptionStyle and variant are missing from Select types.
1 participant