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

feat: add prerender:config, prerender:init and prerender:done hooks #1519

Merged
merged 28 commits into from
Aug 6, 2023

Conversation

harlan-zw
Copy link
Contributor

@harlan-zw harlan-zw commented Aug 1, 2023

πŸ”— Linked issue

Related nuxt/nuxt#22255

❓ 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

An initial step to giving greater prerendering powers to integrations.

Some examples of what this unblocks:

  • emit manifests using data collected during the prerender stage
  • improved error reporting for routes that fail
  • stubbing in modules that are only for the prerender stage

Out of scope of this PR but still to do be done:

  • Close the Prerenderer when it finishes processing all routes
  • Prenderer API exposed on hooks (generateRoute, queueFinished, etc)

πŸ“ Checklist

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

@harlan-zw harlan-zw changed the title feat: Prerenderer hooks feat: prerenderer hooks Aug 1, 2023
@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Merging #1519 (1e638bc) into main (30b3578) will decrease coverage by 0.01%.
Report is 1 commits behind head on main.
The diff coverage is 96.42%.

@@            Coverage Diff             @@
##             main    #1519      +/-   ##
==========================================
- Coverage   76.23%   76.23%   -0.01%     
==========================================
  Files          73       73              
  Lines        7524     7540      +16     
  Branches      739      738       -1     
==========================================
+ Hits         5736     5748      +12     
- Misses       1787     1790       +3     
- Partials        1        2       +1     
Files Changed Coverage Ξ”
src/prerender.ts 85.17% <94.11%> (+0.30%) ⬆️
src/types/nitro.ts 100.00% <100.00%> (ΓΈ)

... and 1 file with indirect coverage changes

@harlan-zw harlan-zw requested review from danielroe and pi0 August 1, 2023 22:14
src/prerender.ts Outdated Show resolved Hide resolved
@pi0 pi0 changed the title feat: prerenderer hooks feat: add prerenderer:config, prerenderer:done and prerenderer:init hooks Aug 2, 2023
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

Beautiful feature idea. I agree with @pi0's comment, but otherwise πŸ‘Œ

Copy link
Contributor

@Hebilicious Hebilicious left a comment

Choose a reason for hiding this comment

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

I love it!
Regarding the hook names, we use the before/done terminology for modules and build, should we use this as a convention ? Or maybe define a new one such as init/finished or before/start ?

src/prerender.ts Outdated Show resolved Hide resolved
@harlan-zw
Copy link
Contributor Author

Yes closing seems a good idea (it will automatically call close hook afterwards). The hook before should be something like done

Should I make a separate PR for this or include it here?

@harlan-zw harlan-zw changed the title feat: add prerenderer:config, prerenderer:close and prerenderer:init hooks feat: add prerenderer:config, prerenderer:done and prerenderer:init hooks Aug 2, 2023
src/prerender.ts Outdated Show resolved Hide resolved
src/prerender.ts Outdated Show resolved Hide resolved
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

LGTM πŸ’― (have to fix failing ci, it needs parent dir creation)

@harlan-zw
Copy link
Contributor Author

harlan-zw commented Aug 2, 2023

LGTM 100 (have to fix failing ci, it needs parent dir creation)

To fix the test properly it would need access to the main nitro instance (not the prerenderer) for the preset output directories πŸ€” A native nitro:init hook that exposes the nitro instance would be a way to solve this without having to add the nitro instance to every hook.

For now, I just removed the test.

@pi0 pi0 changed the title feat: add prerenderer:config, prerenderer:done and prerenderer:init hooks feat: add prerender:config, prerender:init and prerender:done hooks Aug 6, 2023
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thanks again for the PR. I have pushed some relevant refactors on top of it hope it is all fine to you.

@pi0 pi0 merged commit ad5f353 into main Aug 6, 2023
6 checks passed
@pi0 pi0 deleted the feat/prerender-done-hook branch August 6, 2023 19:34
@harlan-zw
Copy link
Contributor Author

Perfect, thank you. I'll think about the prerender controller and if I find some free time and it hasn't been attempted yet, will give it a go.

@pi0 pi0 mentioned this pull request Aug 21, 2023
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.

4 participants