Skip to content

Show error message when JS code fails to load #3044

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

Merged
merged 3 commits into from
Dec 24, 2020
Merged

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Nov 24, 2020

This should resolve #2984, by adding a short error message when something fails to load before the Ember app has booted up:

Bildschirmfoto 2020-11-25 um 00 31 31

This does use an inline script though, so we might have to adjust the CSP for this 😞

r? @jtgeibel

@Turbo87
Copy link
Member Author

Turbo87 commented Nov 26, 2020

I've added a hash of the inline script to the CSP config for nginx, deployed it to staging, and it appears to work :)

@Turbo87 Turbo87 force-pushed the fallback branch 2 times, most recently from 450c614 to a72df88 Compare December 3, 2020 09:31
Copy link
Member

@jtgeibel jtgeibel left a comment

Choose a reason for hiding this comment

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

This works for me locally in Firefox and Chrome when I block the vendor-*.js resource, but this does not work (i.e. blank page only) if I block cargo-*.js.

Additionally, in Firefox only, I see the error None of the “sha512” hashes in the integrity attribute match the content of the subresource. in my console. This is confusing because I don't have CSP enabled in my local environment, and the error seems to be referring to Subresource Integrity. Otherwise the behavior between Chrome and Firefox appears the same, so this may be unrelated.

I don't understand why this appears to rely on cargo.js loading.

My test setup is to run ember build --prod followed by cargo run --bin server and then accessing via http://localhost:8888. This is similar to our production enviornment, sans nginx configuration (like CORS).

@Turbo87
Copy link
Member Author

Turbo87 commented Dec 23, 2020

I've managed to reproduce your issue and I think I understand what's going on:

At least in Chrome, it looks like blocking a URL through the devtools does not cause the onerror handler to be called, instead the request is just silently ignored. The reason why blocking the vendor.js file "worked" is that the cargo.js file depends on code in the vendor.js file, and since that code wasn't there it caused an "Uncaught ReferenceError: define is not defined" error visible on the devtools console.

In other words: blocking the URL through the devtools does not seem to create a realistic failure scenario. The thing we want to test here is having a syntax error in the JS file, so what I did to test this is prefix the content of one of the JS files with e.g. an @ sign so that the browser can't parse it as valid JS anymore. This worked for both cargo.js and vendor.js, so I assume that this is still working as intended.

@jtgeibel
Copy link
Member

Well it sounds like my test steps were fatally flawed then. Thanks for investigating further and adding the comment.

@bors r+

@bors
Copy link
Contributor

bors commented Dec 24, 2020

📌 Commit d425ab5 has been approved by jtgeibel

@bors
Copy link
Contributor

bors commented Dec 24, 2020

⌛ Testing commit d425ab5 with merge 437f5a9...

@bors
Copy link
Contributor

bors commented Dec 24, 2020

☀️ Test successful - checks-actions
Approved by: jtgeibel
Pushing 437f5a9 to master...

@bors bors merged commit 437f5a9 into rust-lang:master Dec 24, 2020
@Turbo87 Turbo87 deleted the fallback branch December 25, 2020 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants