-
Notifications
You must be signed in to change notification settings - Fork 180
remove lazy loading #1018
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
remove lazy loading #1018
Changes from 15 commits
f9746e8
2687031
a453900
44b42e7
fe50017
0c1e85a
1f5097e
65610b5
1a31669
5e4132c
1cb758f
3b755fa
ee75663
0530864
8a64eda
aa1ed33
185822a
da1c094
f3fee6f
b410840
789e98d
1695718
cf72cb7
2ef0748
6180c10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| name: cache-built-deps | ||
| description: Cache built JS artifacts (common + mobile-sdk-alpha) | ||
| inputs: | ||
| cache-version: | ||
| description: Cache version string for cache key | ||
| required: true | ||
| outputs: | ||
| cache-hit: | ||
| description: Whether cache was hit during restore | ||
| value: ${{ steps.restore.outputs.cache-hit }} | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - id: restore | ||
| name: Restore Built Dependencies | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| path: | | ||
| common/dist | ||
| packages/mobile-sdk-alpha/dist | ||
| key: built-deps-${{ inputs.cache-version }}-${{ hashFiles('common/**/*', 'packages/mobile-sdk-alpha/**/*', '!common/dist/**', '!packages/mobile-sdk-alpha/dist/**') }} | ||
| fail-on-cache-miss: false | ||
| - name: Save Built Dependencies | ||
| if: steps.restore.outputs.cache-hit != 'true' | ||
| uses: actions/cache/save@v4 | ||
| with: | ||
| path: | | ||
| common/dist | ||
| packages/mobile-sdk-alpha/dist | ||
| key: built-deps-${{ inputs.cache-version }}-${{ hashFiles('common/**/*', 'packages/mobile-sdk-alpha/**/*', '!common/dist/**', '!packages/mobile-sdk-alpha/dist/**') }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 22 | ||
| 22.12.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,6 +157,7 @@ | |
| "@testing-library/react-native": "^13.3.3", | ||
| "@tsconfig/react-native": "^3.0.6", | ||
| "@types/add": "^2", | ||
| "@types/dompurify": "^3.2.0", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move dompurify to dependencies (runtime), keep @types in devDeps. The web SvgXml wrapper imports dompurify at runtime. Having it in devDependencies risks missing module errors in production web builds and CI. @types/dompurify can stay in devDependencies. Apply: --- a/app/package.json
+++ b/app/package.json
@@
"dependencies": {
@@
+ "dompurify": "^3.2.6",
@@
},
"devDependencies": {
@@
- "dompurify": "^3.2.6",
@@
}Also applies to: 174-174 🤖 Prompt for AI Agents |
||
| "@types/elliptic": "^6", | ||
| "@types/jest": "^29.5.14", | ||
| "@types/node-forge": "^1.3.14", | ||
|
|
@@ -170,6 +171,7 @@ | |
| "@typescript-eslint/parser": "^8.39.0", | ||
| "@vitejs/plugin-react-swc": "^3.10.2", | ||
| "babel-plugin-module-resolver": "^5.0.2", | ||
| "dompurify": "^3.2.6", | ||
| "eslint": "^8.57.0", | ||
| "eslint-config-prettier": "10.1.8", | ||
| "eslint-import-resolver-typescript": "^3.7.0", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | ||
|
|
||
| import React, { forwardRef } from 'react'; | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const { SvgXml: RNSvgXml } = require('react-native-svg'); | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type Props = { | ||
| xml: string; | ||
| width?: number; | ||
| height?: number; | ||
| style?: unknown; | ||
| }; | ||
|
|
||
| export const SvgXml = forwardRef<React.ComponentRef<typeof RNSvgXml>, Props>( | ||
| (p, ref) => <RNSvgXml ref={ref} {...p} />, | ||
| ); | ||
| SvgXml.displayName = 'SvgXml'; | ||
| export default SvgXml; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SPDX-License-Identifier: BUSL-1.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Platform } from 'react-native'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Platform-specific dynamic import | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Platform.OS === 'web') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Web platform - use DOMPurify sanitized version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const webModule = require('@/components/homeScreen/SvgXmlWrapper.web'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| module.exports = webModule; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Native platforms - use react-native-svg directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const nativeModule = require('@/components/homeScreen/SvgXmlWrapper.native'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| module.exports = nativeModule; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Platform-specific dynamic import | |
| if (Platform.OS === 'web') { | |
| // Web platform - use DOMPurify sanitized version | |
| const webModule = require('@/components/homeScreen/SvgXmlWrapper.web'); | |
| module.exports = webModule; | |
| } else { | |
| // Native platforms - use react-native-svg directly | |
| const nativeModule = require('@/components/homeScreen/SvgXmlWrapper.native'); | |
| module.exports = nativeModule; | |
| } | |
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | |
| // SPDX-License-Identifier: BUSL-1.1 | |
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | |
| /* eslint-disable @typescript-eslint/no-require-imports */ | |
| // Platform-specific dynamic import | |
| if (Platform.OS === 'web') { | |
| // Web platform - use DOMPurify sanitized version | |
| const webModule = require('@/components/homeScreen/SvgXmlWrapper.web'); | |
| module.exports = webModule; | |
| } else { | |
| // Native platforms - use react-native-svg directly | |
| const nativeModule = require('@/components/homeScreen/SvgXmlWrapper.native'); | |
| module.exports = nativeModule; | |
| } |
🧰 Tools
🪛 GitHub Check: build-deps
[failure] 14-14:
A require() style import is forbidden
[failure] 10-10:
A require() style import is forbidden
🪛 GitHub Actions: Mobile CI
[error] 10-10: ESLint: '@typescript-eslint/no-require-imports' - A 'require()' style import is forbidden.
🤖 Prompt for AI Agents
In app/src/components/homeScreen/SvgXmlWrapper.ts around lines 7 to 16, this
platform-switching file uses dynamic require() which violates lint rules and is
unnecessary because the bundler resolves SvgXmlWrapper.web/native automatically;
remove this file and update all imports to import from
'@/components/homeScreen/SvgXmlWrapper' (no extension) so Metro/Vite will pick
the correct platform file, then run lint/CI to confirm fixes; if you cannot
remove it immediately, as a short-lived fallback add a top-of-file
eslint-disable for the specific rule and a TODO to delete it once all imports
are updated (preferred: delete).
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SPDX-License-Identifier: BUSL-1.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import DOMPurify from 'dompurify'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import React, { createElement, forwardRef } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type Props = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| xml: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| width?: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| height?: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style?: React.CSSProperties; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } & React.HTMLAttributes<HTMLDivElement>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const SvgXml = forwardRef<HTMLDivElement, Props>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ({ xml, width, height, style, ...props }, ref) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Initialize DOMPurify for web browser environment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const purify = DOMPurify(window); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const safe = purify.sanitize(xml, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| USE_PROFILES: { svg: true, svgFilters: true }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+15
to
+21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard DOMPurify factory for SSR/test environments and avoid re-instantiation. DOMPurify(window) will throw if window is undefined (SSR, some tests). Add a guard and memoize the instance per mount. Apply: -import DOMPurify from 'dompurify';
-import React, { createElement, forwardRef } from 'react';
+import createDOMPurify from 'dompurify';
+import React, { createElement, forwardRef, useMemo } from 'react';
@@
-export const SvgXml = forwardRef<HTMLDivElement, Props>(
- ({ xml, width, height, style, ...props }, ref) => {
- // Initialize DOMPurify for web browser environment
- const purify = DOMPurify(window);
- const safe = purify.sanitize(xml, {
+export const SvgXml = forwardRef<HTMLDivElement, Props>(
+ ({ xml, width, height, style, ...props }, ref) => {
+ const purify = useMemo(
+ () => (typeof window !== 'undefined' ? createDOMPurify(window) : null),
+ [],
+ );
+ const safe = purify?.sanitize(xml, {
USE_PROFILES: { svg: true, svgFilters: true },
- });
+ }) ?? '';📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return createElement('div', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| style: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| width: width || 'auto', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| height: height || 'auto', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display: 'inline-block', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...style, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dangerouslySetInnerHTML: { __html: safe }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...props, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SvgXml.displayName = 'SvgXml'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default SvgXml; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
NDK cache should use a composite and gate installation on cache-hit.
Direct actions/cache calls violate policy and always running
sdkmanagerwastes minutes. Wrap NDK caching in a composite that exposes cache-hit, then install only on miss.New composite (add file .github/actions/cache-ndk/action.yml):