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

chore: add use session example and change tsconfig moduleResolution and module properties to nodenext to allow for @faststore/core/experimental imports. #201

Open
wants to merge 5 commits into
base: api-extensions-setup
Choose a base branch
from

Conversation

icazevedo
Copy link
Contributor

What's the purpose of this pull request?

This PR adds support for experimental imports from @faststore/core/experimental.

How does it work?

Changes moduleResolution and module properties from tsconfig.json to nodenext. It also adds an example to CustomBuyButton component on how to use useSession_unstable.

How to test it?

Browse the PDP on the Deploy Preview. You should be able to see the item id followed by the store's country.

Faststore related PRs

vtex/faststore#2033

References

https://stackoverflow.com/questions/58990498/package-json-exports-field-not-working-with-typescript
https://www.typescriptlang.org/tsconfig#module

…nd module properties to nodenext to allow for @faststore/core/experimental imports.
@icazevedo icazevedo self-assigned this Sep 22, 2023
@icazevedo icazevedo requested a review from a team as a code owner September 22, 2023 17:56
@vercel
Copy link

vercel bot commented Sep 22, 2023

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

Name Status Preview Comments Updated (UTC)
starter ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2023 5:58pm

@vtex-sites
Copy link

vtex-sites bot commented Sep 22, 2023

Lighthouse Reports

Here are the Lighthouse reports of this Pull Request

📝 Based on commit fbf6524

Lighthouse Report by page
📎   /
📎   /apple-magic-mouse/p
📎   /office

icazevedo pushed a commit to vtex/faststore that referenced this pull request Sep 27, 2023
## What's the purpose of this pull request?

This PR fixes an issue where users couldn't import helpful hooks and
components from `@faststore/core` because they were not exported yet.
Most of the hooks were not accessible via `@faststore/sdk`, so users had
no way of doing what they tried to do, such as accessing cart and
session data.

Users could do a few of these hooks themselves, but for the sake of
simplicity, code reuse, and experimentation, they will be made
available.

## How it works?

Import helpful, untested and unoptimized (for this use case, that is,
importing from the starter) hooks & components from
`@faststore/core/experimental`. All exports are appended with
`_unstable` at the end, so it's clear the support is experimental.

To use them, import in a component (override or not) like this:

```tsx
import { useSession_unstable as useSession } from "@faststore/core/experimental";

function MyComponent() {
const session = useSession()
}
```

## How to test it?

Go to this deploy preview and try to use hooks and components exported
by the experimental namespace.

### Starters Deploy Preview

vtex-sites/starter.store#201

## References

I found out that if we export things referenced by the `tsconfig.json`
property `paths`, such as the following, the types for the exported
things wouldn't work, and would be interpreted as any. Moving these
exports to relative path exports fixed the issue.

```tsx
/* Types bugged, says useCart_unstable returns any */
export {
  useCart as useCart_unstable,
  cartStore as cartStore_unstable,
} from 'src/sdk/cart'

/* Types works as expected, useCart_unstable returns correct types */
export {
  useCart as useCart_unstable,
  cartStore as cartStore_unstable,
} from '../../src/sdk/cart'
```
@hellofanny
Copy link
Contributor

@icazevedo is it okay to close this PR? 👁️

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.

3 participants