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

Auto Register stores dir in all layers #2757

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from

Conversation

OsamaHaikal
Copy link

Currently if user did not specify custom storesDir then the expected to auto import stores from stores dir but this is not working inside layers

  1. Added automatic registration of the stores directory across all Nuxt layers.
  2. Updated the documentation to clarify configuration handling with Nuxt layers.

Copy link

netlify bot commented Aug 31, 2024

Deploy Preview for pinia-playground canceled.

Name Link
🔨 Latest commit fed73eb
🔍 Latest deploy log https://app.netlify.com/sites/pinia-playground/deploys/66d2dd1a5654c800083fca7b

Copy link

netlify bot commented Aug 31, 2024

Deploy Preview for pinia-official ready!

Name Link
🔨 Latest commit fed73eb
🔍 Latest deploy log https://app.netlify.com/sites/pinia-official/deploys/66d2dd1a7275c200080aa3b1
😎 Deploy Preview https://deploy-preview-2757--pinia-official.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@OsamaHaikal OsamaHaikal changed the title Enhance working with nuxt layers Auto Register stores dir in all layers Aug 31, 2024
@marr
Copy link

marr commented Sep 19, 2024

will this still register the stores dirs defined in layers if the main app defines it's own storesDirs? It seems like that null check would make it only apply the layers stores when the parent app sets it to null.

@OsamaHaikal
Copy link
Author

OsamaHaikal commented Sep 19, 2024

No because The options are resolved and merged from both the main app (layer) and all other layers. So If the user has defined storeDirs in either the main layer or any additional layer, there is no need to fallback to defaults, as this was the old behavior also

@tommie
Copy link

tommie commented Oct 4, 2024

This looks very good; thanks for writing the patch. I was just hitting this layer issue.

Why change the falsey check into a null check? If you want to keep it so, perhaps use ===.

(I wonder why the second if-statement isn't an else. Might want to clean that up while at it.) Never mind, it's building on the previous one.

@tommie
Copy link

tommie commented Oct 7, 2024

I made this wrapper module to work around this issue: https://gist.github.com/tommie/1e505f3f7a281698bdb9fdc7a303e6c0

@OsamaHaikal
Copy link
Author

Thank you

Why change the falsey check into a null check? If you want to keep it so, perhaps use ===.
I thought that !options..storesDirs is not clear enough and since the need for the check for undefined and null i did ==

if (options.storesDirs == null) {
// Add stores directory for each layer, including the main src dir
options.storesDirs = []
for (const layer of nuxt.options._layers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a public API for layers. I don't know what it is but surely there must be a way to resolve the layers from the options, maybe with a nuxt hook?

Copy link

@wzc520pyfm wzc520pyfm Nov 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nuxt.options._layers seems to be the currently recommended solution for nuxt at present. There are two reasons:

@@ -6,6 +6,7 @@ const counter = useCounter()
useTestStore()
useSomeStoreStore()

const layerStore = useLayerStore()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to change the playground code. We can treat the current playground as a layer. Refer to #2828.
What do you think ?@posva

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not. I will need to take a proper look next time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🧑‍💻 In progress
Development

Successfully merging this pull request may close these issues.

5 participants