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

Scene View better handling for not loading 3D file (including CORS) #521

Merged
merged 22 commits into from
Jun 16, 2022

Conversation

iremgokce
Copy link
Contributor

@iremgokce iremgokce commented Jun 3, 2022

Summary of changes 🔍

  • Changed the request method from fetch to axios since fetch was returning TypeError: Failed to fetch in its catch method without detailed response information. Also since the promise returned from fetch() won't reject on HTTP error status even if the response is an HTTP 404 or 500, it would be better to use axios.
  • However, even with axios's catch block (that falls out of the range of 2xx and when there is no response), it is hard to differentiate the CORS error and other network errors since there is no response returned. I also tried to use XMLHttpRequest to get the status code but it is always 0 for both CORS and network error like offline mode). Therefore, I just changed the content of the error.

References:

image

Testing 🧪

  • Go to ADT 3D Scene Page component and update the 3D file asset url of your scene with some file url, the container of which CORS is not enabled for the origin that you run your code. Easy way is entering a file url which is stored in a container which is different than the one you access your 3d config file and make sure CORS is not enabled for it.

Checklist ✔️

  • Linked associated issue (if present)
  • Added relevant labels
  • Requested developer reviews
  • Request UI review from design / PM
  • Verify all code checks are passing

iremgokce and others added 3 commits June 2, 2022 15:29
Files changed:\nM	src/Resources/Locales/cs.json
M	src/Resources/Locales/de.json
M	src/Resources/Locales/es.json
M	src/Resources/Locales/fr.json
M	src/Resources/Locales/hu.json
M	src/Resources/Locales/it.json
M	src/Resources/Locales/ja.json
M	src/Resources/Locales/ko.json
M	src/Resources/Locales/nl.json
M	src/Resources/Locales/pl.json
M	src/Resources/Locales/pt-pt.json
M	src/Resources/Locales/pt.json
M	src/Resources/Locales/ru.json
M	src/Resources/Locales/sv.json
M	src/Resources/Locales/tr.json
M	src/Resources/Locales/zh-Hans.json
@iremgokce iremgokce added bugfix 🐛 ✅ squashes bug refactor 🔨 Code refactoring labels Jun 3, 2022
@iremgokce iremgokce added this to In progress in Cardboard kanban via automation Jun 3, 2022
@iremgokce iremgokce linked an issue Jun 3, 2022 that may be closed by this pull request
Copy link
Contributor

@darsney darsney left a comment

Choose a reason for hiding this comment

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

Looks fine, just 1 comment

src/Components/3DV/SceneView.tsx Outdated Show resolved Hide resolved
<div className={customStyles.errorMessage}>
Error loading model. Try Ctrl-F5
{loadingError === 'common' && (
<div className={customStyles.commonErrorMessage}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we dont want to use an illustration message for this as well? Probably a different illustartion than the CORS error, but might as well use that component since the styling is nice (vs just literal text)

Copy link
Contributor Author

@iremgokce iremgokce Jun 3, 2022

Choose a reason for hiding this comment

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

yeah, we can :) do you have in mind or I can ask Azima?

src/Components/3DV/SceneView.styles.ts Outdated Show resolved Hide resolved
src/Components/3DV/SceneView.tsx Outdated Show resolved Hide resolved
src/Components/3DV/SceneView.tsx Outdated Show resolved Hide resolved
src/Components/3DV/SceneView.tsx Outdated Show resolved Hide resolved
src/Components/3DV/SceneView.tsx Outdated Show resolved Hide resolved
src/Components/3DV/SceneView.tsx Outdated Show resolved Hide resolved
src/Components/3DV/SceneView.tsx Outdated Show resolved Hide resolved
src/Resources/Locales/en.json Outdated Show resolved Hide resolved
src/Resources/Locales/en.json Outdated Show resolved Hide resolved
src/Resources/Locales/en.json Outdated Show resolved Hide resolved
iremgokce and others added 8 commits June 3, 2022 14:10
Files changed:\nM	src/Resources/Locales/cs.json
M	src/Resources/Locales/de.json
M	src/Resources/Locales/es.json
M	src/Resources/Locales/fr.json
M	src/Resources/Locales/hu.json
M	src/Resources/Locales/it.json
M	src/Resources/Locales/ja.json
M	src/Resources/Locales/ko.json
M	src/Resources/Locales/nl.json
M	src/Resources/Locales/pl.json
M	src/Resources/Locales/pt-pt.json
M	src/Resources/Locales/pt.json
M	src/Resources/Locales/ru.json
M	src/Resources/Locales/sv.json
M	src/Resources/Locales/tr.json
M	src/Resources/Locales/zh-Hans.json
Files changed:\nM	src/Resources/Locales/cs.json
M	src/Resources/Locales/de.json
M	src/Resources/Locales/es.json
M	src/Resources/Locales/fr.json
M	src/Resources/Locales/hu.json
M	src/Resources/Locales/it.json
M	src/Resources/Locales/ja.json
M	src/Resources/Locales/ko.json
M	src/Resources/Locales/nl.json
M	src/Resources/Locales/pl.json
M	src/Resources/Locales/pt-pt.json
M	src/Resources/Locales/pt.json
M	src/Resources/Locales/ru.json
M	src/Resources/Locales/sv.json
M	src/Resources/Locales/tr.json
M	src/Resources/Locales/zh-Hans.json
return dt.toISOString();
})
.catch((error) => {
throw error;
Copy link
Contributor

@ptallettms ptallettms Jun 4, 2022

Choose a reason for hiding this comment

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

So far as I can tell, throwing an error looks a risky change as it promotes the fetch for the modified date to the front line, and fails the load if there's a network error fetching the modified date. I have seen MANY instances where this call fails, but the model load succeeds. I originally had something similar, but backed off that as it failed too many loads.

Please ignore this comment if that is not true.

Copy link
Contributor

@ptallettms ptallettms Jun 4, 2022

Choose a reason for hiding this comment

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

Also this line is technically wrong, but quite nice in practice.

mod = mod ? '?' + mod : '';

If we don't get modified date, we load without a query string which will never cache bust, so if you update the model, we will never load it if the previous version is in cache.

Now actually the getModifiedDate often fails and its a pain to have to keep reloading the model as most of the time, we haven't changed the model, so the behaviour is wrong, but IMHO desirable. If a customer meets this scenario, they can upload the new model with a new name and change their 3DScenesConfig (but better would be to fix their environment so the getModifiedDate works).

If we want to cache bust if the getModifiedDate fails, then this line could be

mod = '?' + mod || new Date().toIsoString();

but I don't like it as most of the time cache busting is not what the user wants, and it fills the cache with loads of copies of the same model (but we could enable the manifest check so it never gets cached at all). I've been meaning to discuss this on standup as I heard a rumour that one of our customers was hitting this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @ptallettms, as you mentioned and we talked with Matt in dev chat, we have decided to move the CORS check logic to Babylon's loader method, but it seems they are swallowing the 403 CORS error in BABYLON.SceneLoader.Load and it is not either falling in its onError or wrapper try/catch blocks catch part. So I just contacted to Babylon team about the issue, hopefully they are going to help with that. Will keep you updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the line above engine.disableManifestCheck = true; is causing the BABYLON.SceneLoader.Load method not surfacing the network error in its onError callback. I asked it to Babylon people and waiting for their reply if they are interconnected. @ptallettms why do we need disabling manifest check, was it for caching related?

Copy link
Contributor Author

@iremgokce iremgokce Jun 16, 2022

Choose a reason for hiding this comment

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

Hey @ptallettms what is you final input on this mod related line? Is mod = '?' + mod || new Date().toIsoString(); better option now? I will keep it as it was originally and let me know if we want to change it, I can do after this PR, since the scope of this PR is handling CORS related error, not improving caching method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Whilst technically incorrect, I'd leave it as it is as that is what the user probably intended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for your reply!

iremgokce and others added 5 commits June 6, 2022 10:45
Files changed:\nM	src/Resources/Locales/cs.json
M	src/Resources/Locales/de.json
M	src/Resources/Locales/es.json
M	src/Resources/Locales/fr.json
M	src/Resources/Locales/hu.json
M	src/Resources/Locales/it.json
M	src/Resources/Locales/ja.json
M	src/Resources/Locales/ko.json
M	src/Resources/Locales/nl.json
M	src/Resources/Locales/pl.json
M	src/Resources/Locales/pt-pt.json
M	src/Resources/Locales/pt.json
M	src/Resources/Locales/ru.json
M	src/Resources/Locales/sv.json
M	src/Resources/Locales/tr.json
M	src/Resources/Locales/zh-Hans.json
Files changed:\nM	src/Resources/Locales/cs.json
M	src/Resources/Locales/de.json
M	src/Resources/Locales/es.json
M	src/Resources/Locales/fr.json
M	src/Resources/Locales/hu.json
M	src/Resources/Locales/it.json
M	src/Resources/Locales/ja.json
M	src/Resources/Locales/ko.json
M	src/Resources/Locales/nl.json
M	src/Resources/Locales/pl.json
M	src/Resources/Locales/pt-pt.json
M	src/Resources/Locales/pt.json
M	src/Resources/Locales/ru.json
M	src/Resources/Locales/sv.json
M	src/Resources/Locales/tr.json
M	src/Resources/Locales/zh-Hans.json
@iremgokce iremgokce marked this pull request as draft June 8, 2022 17:35
@iremgokce
Copy link
Contributor Author

Okay there has been a fix from Babylon team to expose the network error in the loader even caching is enabled @ptallettms @darsney: BabylonJS/Babylon.js#12647 whenever they merge, I will bump up the Babylon version in our package.json and move the CORS/network checking logic to the loader instead of getModifiedTime.

@iremgokce
Copy link
Contributor Author

iremgokce commented Jun 14, 2022

Okay there has been a fix from Babylon team to expose the network error in the loader even caching is enabled @ptallettms @darsney: BabylonJS/Babylon.js#12647 whenever they merge, I will bump up the Babylon version in our package.json and move the CORS/network checking logic to the loader instead of getModifiedTime.

UPDATE: Babylon team is going to publish the fix with Thursday's release: 5.11.0, then I am going to bump Babylon version and move the network error handling logic to loader instead: https://github.com/BabylonJS/Babylon.js/releases/tag/5.11.0

iremgokce and others added 6 commits June 16, 2022 15:11
…row from getModifiedTime axios call beforehand
Files changed:\nM	src/Resources/Locales/cs.json
M	src/Resources/Locales/de.json
M	src/Resources/Locales/es.json
M	src/Resources/Locales/fr.json
M	src/Resources/Locales/hu.json
M	src/Resources/Locales/it.json
M	src/Resources/Locales/ja.json
M	src/Resources/Locales/ko.json
M	src/Resources/Locales/nl.json
M	src/Resources/Locales/pl.json
M	src/Resources/Locales/pt-pt.json
M	src/Resources/Locales/pt.json
M	src/Resources/Locales/ru.json
M	src/Resources/Locales/sv.json
M	src/Resources/Locales/tr.json
M	src/Resources/Locales/zh-Hans.json
Files changed:\nM	src/Resources/Locales/cs.json
M	src/Resources/Locales/de.json
M	src/Resources/Locales/es.json
M	src/Resources/Locales/fr.json
M	src/Resources/Locales/hu.json
M	src/Resources/Locales/it.json
M	src/Resources/Locales/ja.json
M	src/Resources/Locales/ko.json
M	src/Resources/Locales/nl.json
M	src/Resources/Locales/pl.json
M	src/Resources/Locales/pt-pt.json
M	src/Resources/Locales/pt.json
M	src/Resources/Locales/ru.json
M	src/Resources/Locales/sv.json
M	src/Resources/Locales/tr.json
M	src/Resources/Locales/zh-Hans.json
@iremgokce iremgokce marked this pull request as ready for review June 16, 2022 23:00
@iremgokce iremgokce merged commit e057445 into main Jun 16, 2022
Cardboard kanban automation moved this from In progress to Done Jun 16, 2022
@github-actions
Copy link

🎉 This PR is included in version 1.0.0-beta.262 🎉

The release is available on:

Your semantic-release bot 📦🚀

@msnyder-msft msnyder-msft deleted the iremay-scene-view-cors branch September 9, 2022 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

SceneView does not gracefully handle CORS errors
4 participants