Skip to content

Commit

Permalink
fix: Fix PDF export not working on Android
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amanharwara committed Feb 3, 2025
1 parent ca234cd commit a0467e7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 6 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1873,7 +1873,7 @@ SPEC CHECKSUMS:
RNKeychain: a65256b6ca6ba6976132cc4124b238a5b13b3d9c
RNNotifee: f3c01b391dd8e98e67f539f9a35a9cbcd3bae744
RNPrivacySnapshot: 8eaf571478a353f2e5184f5c803164f22428b023
RNShare: 32e97adc8d8c97d4a26bcdd3c45516882184f8b6
RNShare: 0fad69ae2d71de9d1f7b9a43acf876886a6cb99c
RNStoreReview: 923b1c888c13469925bf0256dc2c046eab557ce5
SNReactNative: b5e9e529c175c13f3a618e27c76cf3071213d5e1
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Expand Down
3 changes: 2 additions & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ expose({
renderPDF,
})

export type PDFWorker = {
export type PDFWorkerInterface = {
renderPDF: typeof renderPDF
}
7 changes: 7 additions & 0 deletions packages/web/web.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ module.exports = (env) => {
},
module: {
rules: [
{
test: /\.worker\.tsx?$/,
loader: 'worker-loader',
options: {
inline: 'fallback',
},
},
{
test: /\.(js|tsx?)$/,
/**
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8414,6 +8414,7 @@ __metadata:
webpack: "*"
webpack-dev-server: "*"
webpack-merge: "*"
worker-loader: ^3.0.8
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -28047,6 +28048,18 @@ __metadata:
languageName: node
linkType: hard

"worker-loader@npm:^3.0.8":
version: 3.0.8
resolution: "worker-loader@npm:3.0.8"
dependencies:
loader-utils: ^2.0.0
schema-utils: ^3.0.0
peerDependencies:
webpack: ^4.0.0 || ^5.0.0
checksum: 84f4a7eeb2a1d8b9704425837e017c91eedfae67ac89e0b866a2dcf283323c1dcabe0258196278b7d5fd0041392da895c8a0c59ddf3a94f1b2e003df68ddfec3
languageName: node
linkType: hard

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0, wrap-ansi@npm:^7.0.0":
version: 7.0.0
resolution: "wrap-ansi@npm:7.0.0"
Expand Down

0 comments on commit a0467e7

Please sign in to comment.