-
Notifications
You must be signed in to change notification settings - Fork 11
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
icazevedo
wants to merge
5
commits into
api-extensions-setup
Choose a base branch
from
chore/add-use-session-example
base: api-extensions-setup
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+27
−24
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…nd module properties to nodenext to allow for @faststore/core/experimental imports.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Lighthouse ReportsHere are the Lighthouse reports of this Pull Request📝 Based on commit fbf6524
|
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' ```
emersonlaurentino
approved these changes
Oct 2, 2023
@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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andmodule
properties fromtsconfig.json
tonodenext
. It also adds an example to CustomBuyButton component on how to useuseSession_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