fix: Fix PDF export not working on Android

The request for loading the PDF worker gets canceled since it tries to load it from a `file:` url, so we need to inline the loader as a blob so that it can be loaded correctly.
This commit is contained in:
Aman Harwara
2025-02-03 15:20:33 +05:30
parent ca234cdb33
commit a0467e7c4d
7 changed files with 29 additions and 6 deletions

View File

@@ -1545,7 +1545,7 @@ PODS:
- React-Core
- RNPrivacySnapshot (1.0.0):
- React-Core
- RNShare (9.4.1):
- RNShare (10.2.1):
- React-Core
- RNStoreReview (0.4.1):
- React-Core
@@ -1873,7 +1873,7 @@ SPEC CHECKSUMS:
RNKeychain: a65256b6ca6ba6976132cc4124b238a5b13b3d9c
RNNotifee: f3c01b391dd8e98e67f539f9a35a9cbcd3bae744
RNPrivacySnapshot: 8eaf571478a353f2e5184f5c803164f22428b023
RNShare: 32e97adc8d8c97d4a26bcdd3c45516882184f8b6
RNShare: 0fad69ae2d71de9d1f7b9a43acf876886a6cb99c
RNStoreReview: 923b1c888c13469925bf0256dc2c046eab557ce5
SNReactNative: b5e9e529c175c13f3a618e27c76cf3071213d5e1
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d

View File

@@ -99,7 +99,8 @@
"webextension-polyfill": "^0.10.0",
"webpack": "*",
"webpack-dev-server": "*",
"webpack-merge": "*"
"webpack-merge": "*",
"worker-loader": "^3.0.8"
},
"lint-staged": {
"app/**/*.{js,ts,jsx,tsx}": "eslint --cache --fix",

View File

@@ -19,7 +19,8 @@ import { $isRemoteImageNode } from '../../../Plugins/RemoteImagePlugin/RemoteIma
import { $isCollapsibleContainerNode } from '../../../Plugins/CollapsiblePlugin/CollapsibleContainerNode'
import { $isCollapsibleContentNode } from '../../../Plugins/CollapsiblePlugin/CollapsibleContentNode'
import { $isCollapsibleTitleNode } from '../../../Plugins/CollapsiblePlugin/CollapsibleTitleNode'
import { PDFDataNode, PDFWorker } from './PDFWorker'
// @ts-expect-error TS thinks there's no default export but that is added by the webpack loader.
import PDFWorker, { PDFDataNode, PDFWorkerInterface } from './PDFWorker.worker'
import { wrap } from 'comlink'
import { PrefKey, PrefValue } from '@standardnotes/snjs'
@@ -417,7 +418,8 @@ const getPDFDataNodesFromLexicalNodes = (nodes: LexicalNode[]): PDFDataNode[] =>
return nodes.map(getPDFDataNodeFromLexicalNode)
}
const PDFWorkerComlink = wrap<PDFWorker>(new Worker(new URL('./PDFWorker.tsx', import.meta.url)))
const pdfWorker = new PDFWorker()
const PDFWorkerComlink = wrap<PDFWorkerInterface>(pdfWorker)
/**
* @returns The PDF as an object url

View File

@@ -102,6 +102,6 @@ expose({
renderPDF,
})
export type PDFWorker = {
export type PDFWorkerInterface = {
renderPDF: typeof renderPDF
}

View File

@@ -92,6 +92,13 @@ module.exports = (env) => {
},
module: {
rules: [
{
test: /\.worker\.tsx?$/,
loader: 'worker-loader',
options: {
inline: 'fallback',
},
},
{
test: /\.(js|tsx?)$/,
/**