Skip to content

fix(plugin-preview): support QR code scanning on mobile devices and first screen SSR#3098

Merged
SoonIter merged 1 commit intomainfrom
syt/update-qr-code
Feb 2, 2026
Merged

fix(plugin-preview): support QR code scanning on mobile devices and first screen SSR#3098
SoonIter merged 1 commit intomainfrom
syt/update-qr-code

Conversation

@SoonIter
Copy link
Copy Markdown
Member

@SoonIter SoonIter commented Feb 2, 2026

Summary

  • Replace hardcoded localhost with window.location.hostname in iframe URLs, enabling mobile devices to access previews via QR code on the local network
  • Set dev server host: true to listen on all network interfaces
  • Extract shared getPageUrl/getPageFullUrl utility and use source.define instead of extendPageData for passing dev port

Before

QR Code content

/~demo/_components_button

After

QR Code content

https://rspress.rs/~demo/_components_button

image

…evice scanning

Replace hardcoded localhost with window.location.hostname and set dev server host to true, enabling QR code scanning from mobile devices on the local network. Extract shared getPageUrl utility and use define instead of extendPageData for dev port.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 2, 2026 09:23
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying rspress-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 90ddbd1
Status: ✅  Deploy successful!
Preview URL: https://03863f03.rspress-v2.pages.dev
Branch Preview URL: https://syt-update-qr-code.rspress-v2.pages.dev

View logs

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 2, 2026

Rsdoctor Bundle Diff Analysis

Found 3 projects in monorepo, 2 projects with changes.

📊 Quick Summary
Project Total Size Change
node 11.6 MB 📈 +401.5 KB (+3.5%)
node_md 1.5 MB 0
web 15.7 MB -5.3 KB (-0.0%)
📋 Detailed Reports (Click to expand)

📁 node

Path: website/doc_build/diff-rsdoctor/node/rsdoctor-data.json

📌 Baseline Commit: 9ec8c3d2b4 | PR: #3096

Metric Current Baseline Change
📊 Total Size 11.6 MB 11.2 MB +401.5 KB (+3.5%)
📄 JavaScript 0 B 0 B 0
🎨 CSS 0 B 0 B 0
🌐 HTML 11.6 MB 11.2 MB +401.5 KB (+3.5%)
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: node Bundle Diff

📁 web

Path: website/doc_build/diff-rsdoctor/web/rsdoctor-data.json

📌 Baseline Commit: 9ec8c3d2b4 | PR: #3096

Metric Current Baseline Change
📊 Total Size 15.7 MB 15.7 MB -5.3 KB (-0.0%)
📄 JavaScript 15.5 MB 15.5 MB -5.3 KB (-0.0%)
🎨 CSS 119.3 KB 119.3 KB 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 159.8 KB 159.8 KB 0

📦 Download Diff Report: web Bundle Diff

Generated by Rsdoctor GitHub Action

@SoonIter SoonIter changed the title fix(plugin-preview): support QR code scanning on mobile devices fix(plugin-preview): support QR code scanning on mobile devices and first screen SSR Feb 2, 2026
@SoonIter SoonIter enabled auto-merge (squash) February 2, 2026 09:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the @rspress/plugin-preview behavior so that preview iframes and QR codes work correctly on mobile devices accessing the dev server over the local network, and refactors how the dev port is propagated into the client code.

Changes:

  • Added a shared getPageUrl/getPageFullUrl helper to centralize preview URL construction, using window.location.hostname plus an injected RSPRESS_IFRAME_DEV_PORT in development, and withBase('/~demo/...') in other cases.
  • Updated Preview and FixedDevice components to use the new helpers and dropped the previous NoSSR wrapper and page.devPort wiring.
  • Configured the preview dev server with host: true to bind to all interfaces and injects process.env.RSPRESS_IFRAME_DEV_PORT via source.define instead of mutating page data with extendPageData.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/plugin-preview/static/global-components/common/getPageUrl.ts New utility that builds relative and full preview URLs for demos in dev and production, using the defined dev port and current hostname.
packages/plugin-preview/static/global-components/Preview.tsx Simplified preview component props and logic to compute iframe/QR URLs via the shared helper and removed the NoSSR wrapper now that URL logic is centrally handled.
packages/plugin-preview/static/global-components/FixedDevice.tsx Reused the shared URL helper for fixed-device previews and QR codes, removing inline URL construction and the NoSSR wrapper.
packages/plugin-preview/src/index.ts Updated preview plugin configuration to run the iframe dev server on all interfaces, inject the iframe dev port via source.define, and remove the extendPageData shim for page.devPort.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SoonIter SoonIter merged commit a9bce47 into main Feb 2, 2026
16 checks passed
@SoonIter SoonIter deleted the syt/update-qr-code branch February 2, 2026 09:37
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.

3 participants