Skip to content

Use nanonext http server for preview#2975

Merged
shikokuchuo merged 5 commits intor-lib:mainfrom
shikokuchuo:http-server
Mar 2, 2026
Merged

Use nanonext http server for preview#2975
shikokuchuo merged 5 commits intor-lib:mainfrom
shikokuchuo:http-server

Conversation

@shikokuchuo
Copy link
Member

@shikokuchuo shikokuchuo commented Feb 23, 2026

Summary

  • Serve previewed sites over http://127.0.0.1 (ephemeral port) instead of opening file:// paths directly, enabling dynamic features like the Algolia search bar that require HTTP to function.
  • The server persists across preview_site() calls for the same site root and is replaced when switching sites.
  • Uses a lightweight C-level static directory server, bypassing R entirely after creation.
  • Adds nanonext (>= 1.8.0) to Imports.

Details

  • A package-level environment (the) caches the active server and its root path across calls within a session.
  • stop_preview() explicitly closes the server. It's exported for manual use but not strictly necessary as the server is automatically replaced when switching sites and closed when the R session ends.
  • New tests cover server creation, reuse, replacement on root change, stop_preview() cleanup, and URL construction for sub-paths.

@maelle
Copy link
Collaborator

maelle commented Feb 24, 2026

Cool! Another docs section that would need updating: https://pkgdown.r-lib.org/reference/build_search.html#debugging-and-local-testing

@shikokuchuo
Copy link
Member Author

@maelle thanks, updated now.

@shikokuchuo shikokuchuo requested a review from hadley March 2, 2026 09:31
@shikokuchuo shikokuchuo merged commit a6abe43 into r-lib:main Mar 2, 2026
16 checks passed
@shikokuchuo shikokuchuo deleted the http-server branch March 2, 2026 21:33
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