Skip to content

Conversation

@ulivz
Copy link
Member

@ulivz ulivz commented Oct 11, 2025

Summary

Optimized Showcase page performance by implementing build-time data fetching using Rspress addRuntimeModules hook, eliminating runtime API calls and improving user experience.

Changes

  • Virtual Module Plugin: Added showcase-data-plugin using addRuntimeModules hook
  • Optimized Hook: Created useShowcaseDataOptimized that imports from virtual module
  • Fallback Strategy: Maintains runtime API calls for specific sessionId/slug requests
  • Performance: Eliminated runtime API calls for public showcase listings

Performance Impact

  • Instant Loading: Showcase items appear immediately without spinner
  • Reduced Network: No API calls for public showcase page
  • Resilient: Works even if API is temporarily unavailable
  • Build-time Fetch: Data fetched once during build, included in bundle

Technical Implementation

  • Uses Rspress addRuntimeModules hook to create virtual module showcase-data
  • Virtual module contains showcase data as JavaScript export
  • Hook imports directly from virtual module for instant access
  • Preserves backward compatibility with existing components

Plugin Code

async addRuntimeModules() {
  const data = await fetchShowcaseData();
  return {
    'showcase-data': `export const showcaseData = ${JSON.stringify(data)};`
  };
}

Hook Usage

import { showcaseData } from 'showcase-data';

Files Changed

  • plugins/showcase-data-plugin.ts - Virtual module creation
  • src/hooks/useShowcaseDataOptimized.ts - Virtual module consumer
  • src/components/Showcase/index.tsx - Updated to use optimized hook
  • env.d.ts - Virtual module type declarations
  • rspress.config.ts - Plugin configuration
  • SHOWCASE_OPTIMIZATION.md - Updated documentation

Checklist

  • Added or updated necessary tests (Optional).
  • Updated documentation to align with changes (Optional).
  • Verified no breaking changes, or prepared solutions for any occurring breaking changes (Optional).
  • My change does not involve the above items.

ulivz added 2 commits October 11, 2025 15:22
- Add showcase-data-plugin to fetch data during build
- Create optimized hook using build-time injected data
- Fallback to runtime API for specific sessionId/slug
- Improve performance by eliminating runtime API calls for public showcase
@netlify
Copy link

netlify bot commented Oct 11, 2025

Deploy Preview for tarko ready!

Name Link
🔨 Latest commit 1cd2173
🔍 Latest deploy log https://app.netlify.com/projects/tarko/deploys/68ea14fc4de4730008da5275
😎 Deploy Preview https://deploy-preview-1714--tarko.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 project configuration.

@netlify
Copy link

netlify bot commented Oct 11, 2025

Deploy Preview for agent-tars-docs ready!

Name Link
🔨 Latest commit 1cd2173
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/68ea14fcd728530008352141
😎 Deploy Preview https://deploy-preview-1714--agent-tars-docs.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 project configuration.

- Switch from file-based to virtual module approach
- Use addRuntimeModules hook as per Rspress best practices
- Remove physical file generation, use virtual modules
- Update documentation to reflect correct implementation
@ulivz ulivz changed the title feat(docs): showcase build-time optimization docs(agent-tars): showcase build-time optimization Oct 11, 2025
@ulivz ulivz merged commit 1fef3d7 into main Oct 11, 2025
10 checks passed
@ulivz ulivz deleted the feat/showcase-build-time-optimization branch October 11, 2025 08:35
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.

2 participants