perf: use dynamic imports for stellar-sdk signing logic (#622) - #1034
Open
Richiey1 wants to merge 4 commits into
Open
perf: use dynamic imports for stellar-sdk signing logic (#622)#1034Richiey1 wants to merge 4 commits into
Richiey1 wants to merge 4 commits into
Conversation
Add fr and pt locales to routing configuration. Create translation files for French and Portuguese (copied from en as base). LanguageSwitcher automatically detects new locales from routing config. Closes Iris-IV#680
… routes (Iris-IV#670) - Add pagination (page/pageSize), status filtering, and sparse field selection to GET /api/reports - Add pagination (page/pageSize), adminAddress/action filtering, and sparse field selection to GET /api/admin-audit-log - Update client-side getAdminAuditLog to request paginated pages instead of fetching the full dataset - Return { items, total, page, pageSize, hasMore } envelope from both endpoints - Add unit tests covering pagination, filtering, sparse fieldsets, and pageSize clamping
…ges (Iris-IV#650) - Add refetchInterval: 15s to useCampaignComments query for real-time updates - Set refetchIntervalInBackground: false to avoid polling when tab is hidden - Set staleTime: 0 to ensure fresh data on each poll - Add creatorAddress prop to CommentItem and CommentsList - Show a blue "Creator" badge on comments from the campaign creator - Pass campaign.creator as creatorAddress from CommentsSection
- Replace static with dynamic in signing/verification functions - offchainApiClient.ts: signOffchainPayload loads SDK on demand - campaignComments.ts: verifyCommentSignature loads SDK on demand - campaignUpdates.ts: verifyUpdateSignature loads SDK on demand - WalletContext.tsx: mock keypair generation loads SDK on demand - AdminClient.tsx: address validation loads SDK on demand - This reduces the initial client bundle size by deferring the heavy SDK until signing is actually needed
|
@Richiey1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Auto-review failed (API error). Leaving PR for human review. |
| @@ -0,0 +1,132 @@ | |||
| import { NextResponse } from "next/server"; | |||
| @@ -0,0 +1,112 @@ | |||
| import { NextResponse } from "next/server"; | |||
| if (apiEntries.length > 0) { | ||
| writeAllEntries(apiEntries); | ||
| return apiEntries.sort((a, b) => b.timestamp - a.timestamp).slice(0, Math.max(0, limit)); | ||
| const { entries, total, hasMore } = await readApiEntries(normalizedAddress, page, pageSize); |
davidmaronio
requested changes
Aug 4, 2026
davidmaronio
left a comment
Contributor
There was a problem hiding this comment.
the idea is right and most of the mechanical work is good: the cached getStellarSdk() helper pattern in campaignComments.ts, campaignUpdates.ts and offchainApiClient.ts is exactly how to defer stellar-sdk out of the initial bundle, and dropping the top-level import in AdminClient.tsx for a one-off validity check is a nice win.
blockers:
- src/components/WalletContext.tsx: this file's diff is mangled, it was produced against an old version of the file. it adds a second
import React, { createContext, ... }line below the existing one, splices in an orphaninterface WalletContextType {fragment against the current WalletStateContext/WalletActionsContext structure, and references IS_MOCK_MODE above its import. this is what produces the "Expression expected" parse errors at WalletContext.tsx line 60 in CI. the PR is also marked conflicting. please redo this file against current main. - src/lib/offchainApiClient.ts:124
as sdk.Transactionis invalid:sdkis a runtime value here, not a type namespace, so tsc rejects it. useimport type { Transaction } from "@stellar/stellar-sdk"(type-only imports do not defeat the dynamic import) and cast to that. - src/app/[locale]/admin/AdminClient.tsx:334 raw
await import("@stellar/stellar-sdk")here while everywhere else uses the cached helper. minor, but consider a shared getStellarSdk in one lib module instead of four copies of the same memoization. - the PR is stacked on #1033, #1032 and #1028 (comments files, api routes, untranslated fr/pt). please rebase so only the dynamic-import work remains, it is not mergeable independently as is.
- after the fixes, please include a before/after from the bundle-size check in the PR description so the win from #622 is verifiable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #622
Summary
Reduced the initial client bundle size by replacing static
@stellar/stellar-sdkimports with dynamic imports in signing and verification functions. The SDK is now only loaded when actually needed for cryptographic operations, not on initial page load.What changed
src/lib/offchainApiClient.ts:signOffchainPayloadnow dynamically imports@stellar/stellar-sdkon first call and caches the resultsrc/lib/campaignComments.ts:verifyCommentSignaturenow dynamically imports the SDK on first callsrc/lib/campaignUpdates.ts:verifyUpdateSignaturenow dynamically imports the SDK on first callsrc/components/WalletContext.tsx: Mock keypair generation now dynamically imports the SDK on first callsrc/app/[locale]/admin/AdminClient.tsx: Address validation now dynamically imports the SDK on first callHow it works
Each function that needs the SDK calls
await import("@stellar/stellar-sdk")instead of using a static top-level import. The result is cached in a module-level variable so subsequent calls don't re-load the module. This means:Verification
npm run lint— no new warnings or errors introducednpm run typecheck— no new type errors in modified files (pre-existing errors in WalletContext.tsx remain unchanged)npm run test -- --testPathPatterns="src/__tests__/app/api"— existing pagination tests still passHey @FinesseStudioLab/maintainer, this closes #622. Let me know if you'd like any adjustments to the caching strategy or if there are other signing paths you'd like to convert.