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(nuxt): allow pages:extend to enable pages module #20806

Merged
merged 23 commits into from May 15, 2023

Conversation

darioferderber
Copy link
Contributor

πŸ”— Linked issue

resolves #20801

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Sets pages option to true if extendPages is called.
If extendPages gets called, it means that there are actually some pages, so we can set te pages option to true?

+ updates typo in documentation

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@nuxt-studio
Copy link

nuxt-studio bot commented May 12, 2023

βœ… Live Preview ready!

Name Edit Preview Latest Commit
Nuxt Docs Edit on Studio β†—οΈŽ View Live Preview d0b97a4

@edgarsn
Copy link

edgarsn commented May 12, 2023

Thank you for your fast work, but I think there's one edge case left behind which is not my case, but may happen to others later.

You can also extend pages by using hook - pages:extend instead of extendPages() function.

Shouldn't it be better to set it after await nuxt.callHook('pages:extend', pages) here ? If pages array after hook call is not empty, then surely we can set nuxt.options.pages = true; right?

@darioferderber
Copy link
Contributor Author

darioferderber commented May 12, 2023

@edgarsn you're right!
this line you've mentioned will never get triggered in the dev mode, so it surely isn't a place to set nuxt.options.pages to true.

The problem is that isPagesEnabled function scans the pages directory before pages:extend hook is even called and returns if there are no pages (it returns too early).

I'll try to figure something out πŸ™‚

Edit:
@danielroe are there any concerns if the hook gets called multiple times? Because I've tested it and even though the hook gets called multiple times, it won't push the same page into the array.

If it's like that, then the hook can be called inside the isPagesEnabled function, and that would eventually resolve the issue.

@danielroe
Copy link
Member

The safest thing is probably to do this within isPagesEnabled, directly before returning false:

const pages = await resolvePagesRoutes()
await nuxt.callHook('pages:extend', pages)
if (pages.length) {
  return true
}

We can keep the previous early returns for true as a more performant fast-path.

@darioferderber
Copy link
Contributor Author

I agree, but that means that the hook will be called multiple times if there are no pages, so I wasn't sure if that's a good idea.

@danielroe danielroe changed the title feat(kit): use pages from the module without setting the pages option to true fix(nuxt): allow pages:extend to enable pages module May 15, 2023
@danielroe danielroe merged commit ec9dcdb into nuxt:main May 15, 2023
19 checks passed
This was referenced May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<NuxtPage> info message does not look up for module pages
3 participants