Skip to content
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

Load pdfjs webworker script from source #13546

Merged
merged 1 commit into from
Dec 15, 2022
Merged

Conversation

marcaaron
Copy link
Contributor

@marcaaron marcaaron commented Dec 13, 2022

Details

When someone goes offline before opening the attachment modal they are unable to load the web workers script via HTTPS. This fix allows loading the worker source as a string in the bundle so it can be used later even if we are offline.

Fixed Issues

$ #12512

Tests

Same as QA.

Note: Use a VALID PDF i.e. something that normally works fine while we are online.

I would recommend sending yourself a valid PDF to an iOS and Android device + hosting the local web version via NGROK then test selecting the attachment with the internet disabled (i.e. Wi-Fi disabled).

  • Verify that no errors appear in the JS console

Offline tests

This is related to offline behavior so QA is the same.

QA Steps

  1. Open any chat in the new dot
  2. Go offline
  3. Click ➕ in composer -> Add Attachments
  4. Select a VALID PDF attachment
  5. Verify that a preview shows and there is no "Failed to load PDF file" text
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

2022-12-12_14-45-27

Mobile Web - Chrome

Works. But looks messed up atm and is missing the submit button.

Screenshot_20221212-151035_Chrome

Mobile Web - Safari

image_123986672 (1)

Desktop

2022-12-12_15-07-48

iOS

N/A as this platform is not touched in this PR

Android

N/A as this platform is not touched in this PR

@marcaaron marcaaron self-assigned this Dec 13, 2022
@melvin-bot
Copy link

melvin-bot bot commented Dec 13, 2022

Hey, I noticed you changed some webpack configuration files. This can break production builds. Did you remember to run a production build locally to verify they still work?

@marcaaron
Copy link
Contributor Author

This is ready for review now. While QA-ing this I discovered that there is an existing issue on staging/production where if someone goes Offline the "Send" button disappears on the "Send attachment" screen. This is an Android only issue. I'll try to figure it out tomorrow - if not we can report a new issue.

@marcaaron marcaaron marked this pull request as ready for review December 13, 2022 01:22
@marcaaron marcaaron requested a review from a team as a code owner December 13, 2022 01:22
@melvin-bot melvin-bot bot requested review from aimane-chnaif and danieldoglas and removed request for a team December 13, 2022 01:23
@melvin-bot
Copy link

melvin-bot bot commented Dec 13, 2022

@aimane-chnaif @danieldoglas One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@aimane-chnaif
Copy link
Contributor

Testing blocked on web, mWeb because of this known issue (403 auth error)

@marcaaron
Copy link
Contributor Author

Bump for reviews

Copy link
Contributor

@aimane-chnaif aimane-chnaif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm original issue is fixed by this PR on all platforms.
But 2 issues here as mentioned earlier:

  • Stuck on Uploading Attachment... after send
    bug1

  • Send button is hidden on android chrome

mchrome.mp4

@marcaaron
Copy link
Contributor Author

@aimane-chnaif I don't think either of those are blockers for this issue and we can continue with the checklist + testing

@aimane-chnaif
Copy link
Contributor

aimane-chnaif commented Dec 14, 2022

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web web
Mobile Web - Chrome
mchrome.mp4
Mobile Web - Safari
msafari.mp4
Desktop desktop
iOS
ios.mp4
Android
android.mp4

@aimane-chnaif
Copy link
Contributor

Tests well on all platforms.
As webpack file changed, will try run a production build locally as a last step.

@aimane-chnaif
Copy link
Contributor

Screenshot 2022-12-14 at 10 24 24 PM

@marcaaron can we ignore this warning?

@aimane-chnaif
Copy link
Contributor

In dev, shows this console warning:
DevTools failed to load source map: Could not load content for http://localhost:8080/pdf.worker.js.map: Fetch through target failed: Target not supported; Fallback: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

In prod build, shows this:
DevTools failed to load source map: Could not parse content for http://localhost:3000/pdf.worker.js.map: Unexpected token '<', "<!doctype "... is not valid JSON

@marcaaron
Copy link
Contributor Author

Hmm I'm not really sure what that is about or how to get rid of it - if it doesn't affect the app I'm not sure we need to prioritize it.

Copy link
Contributor

@danieldoglas danieldoglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@danieldoglas danieldoglas merged commit e9da529 into main Dec 15, 2022
@danieldoglas danieldoglas deleted the marcaaron-fixPDFPreview branch December 15, 2022 18:27
@danieldoglas
Copy link
Contributor

I don't think we need to prioritize that error as well.

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions
Copy link
Contributor

Performance Comparison Report 📊

Significant Changes To Duration

There are no entries

Meaningless Changes To Duration

Show entries
Name Duration
TTI 786.342 ms → 802.427 ms (+16.085 ms, +2.0%)
runJsBundle 186.938 ms → 195.313 ms (+8.375 ms, +4.5%)
nativeLaunch 9.531 ms → 9.594 ms (+0.063 ms, +0.7%)
regularAppStart 0.013 ms → 0.014 ms (+0.000 ms, +2.3%)
Show details
Name Duration
TTI Baseline
Mean: 786.342 ms
Stdev: 31.991 ms (4.1%)
Runs: 726.9957149997354 739.8276140000671 742.039358000271 746.6596480002627 749.9644860001281 751.3401910001412 756.6752690002322 759.2016759999096 761.6203349996358 764.2002100003883 766.4053870001808 768.2130260001868 780.7096539996564 786.38454800006 786.8070750003681 789.7046189997345 790.4842550000176 791.2827540002763 791.6049849996343 795.9263469995931 796.0106509998441 797.4983320003375 800.2959900000133 815.2977139996365 819.3230229998007 822.400723000057 827.1260399995372 827.915195999667 834.2663369998336 840.2861810000613 850.1345330001786

Current
Mean: 802.427 ms
Stdev: 30.166 ms (3.8%)
Runs: 749.7431370001286 755.4479069998488 759.5627410002053 762.8087600003928 766.0803460003808 766.2216910002753 775.991836999543 783.9891980001703 786.3099980000407 787.058246999979 787.9281829996035 788.2390630003065 797.2099310001358 798.0311500001699 800.5792309995741 804.204841000028 808.1418300000951 811.6748400004581 813.1766280001029 814.9647800000384 816.8231490002945 817.4986629998311 823.3582450002432 824.4460629997775 826.5555060002953 833.507895000279 840.5609269998968 841.1376569997519 865.3327379999682 866.2368839997798
runJsBundle Baseline
Mean: 186.938 ms
Stdev: 21.754 ms (11.6%)
Runs: 154 162 163 165 166 166 169 170 170 171 173 173 177 177 177 178 180 182 184 188 188 189 195 203 211 211 219 220 222 223 228 228

Current
Mean: 195.313 ms
Stdev: 25.827 ms (13.2%)
Runs: 159 162 168 170 170 170 171 171 173 176 177 179 182 186 189 190 193 194 195 196 198 207 212 215 215 216 217 219 226 239 255 260
nativeLaunch Baseline
Mean: 9.531 ms
Stdev: 1.346 ms (14.1%)
Runs: 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 11 11 11 11 11 12 12 12

Current
Mean: 9.594 ms
Stdev: 1.343 ms (14.0%)
Runs: 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 11 11 11 11 11 12 12 12 12
regularAppStart Baseline
Mean: 0.013 ms
Stdev: 0.001 ms (6.3%)
Runs: 0.012084999587386847 0.01220700005069375 0.012207000516355038 0.012450999580323696 0.012531999498605728 0.012776999734342098 0.012817000038921833 0.0129399998113513 0.012980000115931034 0.013061000034213066 0.013062000274658203 0.013143000192940235 0.013264999724924564 0.0133050000295043 0.013345999643206596 0.013345999643206596 0.013346999883651733 0.013387000188231468 0.01342800073325634 0.0134680001065135 0.013468999415636063 0.013549000024795532 0.013590999878942966 0.013875000178813934 0.013957000337541103 0.014241999946534634 0.014810999855399132 0.014810999855399132 0.014810999855399132 0.014891999773681164 0.015665999613702297

Current
Mean: 0.014 ms
Stdev: 0.001 ms (6.1%)
Runs: 0.012369000352919102 0.012655000202357769 0.012776999734342098 0.01281800027936697 0.012858000583946705 0.013020999729633331 0.013020999729633331 0.013020999729633331 0.013020999729633331 0.013061999343335629 0.013143000192940235 0.013345999643206596 0.013387000188231468 0.013387000188231468 0.013508999720215797 0.01375299971550703 0.013794000260531902 0.013876000419259071 0.013915999792516232 0.013956000097095966 0.013996999710798264 0.014120000414550304 0.014120000414550304 0.014161000028252602 0.014201000332832336 0.014364000409841537 0.014485999941825867 0.014933000318706036 0.014973999932408333 0.014973999932408333 0.015178000554442406 0.015951000154018402

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @danieldoglas in version: 1.2.41-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @danieldoglas in version: 1.2.41-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@aimane-chnaif
Copy link
Contributor

I think this PR caused regression - #13665

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @yuwenmemon in version: 1.2.41-4 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@marcaaron
Copy link
Contributor Author

I don't think this was deployed to production because we reverted it...

@marcaaron marcaaron mentioned this pull request Jan 25, 2023
54 tasks
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.

4 participants