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

Submit new profile will not work on Chrome #781

Closed
bdavidxyz opened this issue Feb 14, 2023 · 8 comments
Closed

Submit new profile will not work on Chrome #781

bdavidxyz opened this issue Feb 14, 2023 · 8 comments
Assignees
Labels
bug Something isn't working good first issue Good for first time contributors help wanted Looking for help from the community

Comments

@bdavidxyz
Copy link

Describe the bug

If you create a new developer profile, then the main form submit will not work on Chrome, because 1) the avatar field is mandatory 2) the avatar field uses createObjectURL, which is not tolerated anymore for a media object on Chrome.

To reproduce

Steps to reproduce the behavior:

  1. Use Google Chrome
  2. Register
  3. Click on "I'm looking for work"
  4. Fill the whole form, scroll down to 'Save', and click on 'Save'.
  5. See error

Expected behavior

The profile is successfully created

Actual behavior

Avatar field is in error. Chrome Console shows : Failed to execute 'createObjectURL' on 'URL'

See StackOverflow answer : https://stackoverflow.com/a/53821674/2595513
"This error is caused because the function createObjectURL no longer accepts media stream object for Google Chrome"

Please note that there are no bug when using Firefox.

Screenshots

I don't have a screenshot, alas

Additional context

No additional context

@bdavidxyz bdavidxyz added the bug Something isn't working label Feb 14, 2023
@joemasilotti
Copy link
Owner

Thanks for reporting this!

I just ran through in Chrome and was able to create my profile without issue. However, I didn't see the photo preview when I selected one from disk.

Regardless, I'd like to get this fixed. If you (or anyone else) wants to get this fixed then please comment on this issue.

@joemasilotti joemasilotti added help wanted Looking for help from the community good first issue Good for first time contributors labels Feb 16, 2023
@ryy
Copy link
Contributor

ryy commented Feb 17, 2023

Hi, I'm interested in working on the "I didn't see the photo preview when I selected one from disk." issue. Is it still available?

Maybe, we need to update not only the src attribute inside the img tag but also the src attribute of the source tag.

<!-- avatar -->
<picture>
  <!--  we have to update src of source tag -->
  <source media="(-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx)" srcset="avatar.jpeg"> 

  <!-- only change to src of img tag in app/javascript/controllers/file_upload_controller.js -->
  <img alt="Developer's avatar" data-file-upload-target="image" class="h-24 w-24 sm:h-32 sm:w-32 ring-4 ring-white object-cover rounded-full bg-gray-300" src="avatar.jpeg">
</picture>

@joemasilotti
Copy link
Owner

Oh, good call @ryy! Can you submit a PR so I can test it out?

@ryy
Copy link
Contributor

ryy commented Feb 17, 2023

@joemasilotti

I'm sorry.
I would like to write a system test but it's not working and is taking a long time. Headless-chrome will not start😱
I'll just post the diffs🙏

select(event) {
const file = event.currentTarget.files[0]
this.imageTarget.src = window.URL.createObjectURL(file)
this.imageTarget.srcset = window.URL.createObjectURL(file)
this.imageTarget.classList.remove(this.visibilityClass)
this.errorTarget.classList.add(this.visibilityClass)
}

// railsdevs.com/app/javascript/controllers/file_upload_controller.js
  select(event) {
    const file = event.currentTarget.files[0]
    this.imageTarget.src = window.URL.createObjectURL(file)
    this.imageTarget.srcset = window.URL.createObjectURL(file)
+  const picture = event.currentTarget.closest('div').querySelector('picture');
+  if(picture) {
+    const sources = picture.querySelectorAll('source');
+    sources.forEach(source => {
+      source.srcset = window.URL.createObjectURL(file);
+    });
+  }
    this.imageTarget.classList.remove(this.visibilityClass)
    this.errorTarget.classList.add(this.visibilityClass)
  }

@joemasilotti
Copy link
Owner

@ryy, don't worry about a system test for this.

Can you please submit a PR without it so I can review and merge? Thanks!

@ryy
Copy link
Contributor

ryy commented Feb 26, 2023

@joemasilotti
I've just submitted a PR!

@joemasilotti
Copy link
Owner

Awesome, thanks! I’ll review soon.

@joemasilotti
Copy link
Owner

Closed via #787.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for first time contributors help wanted Looking for help from the community
Projects
Status: In progress
Development

No branches or pull requests

3 participants