silverstripe / silverstripe-s3

Silverstripe module to store assets in S3 rather than on the local filesystem (SS4/SS5 only)
BSD 3-Clause "New" or "Revised" License
20 stars 25 forks source link

SilverStripe 4.1.x and Silverstripe-S3 module - TinyMCE WYSIWYG doesn't load on initial CMS Load #18

Closed kinglozzer closed 5 years ago

kinglozzer commented 6 years ago

From @obj63mc on May 29, 2018 21:32

Currently testing using v4.1.x and dev/master of silverstripe-s3.

I wasn't sure where the best place to log this issue but assuming it will probably need to be moved to a fix in silverstripe/framework as it is an issue with the HTMLEditorField, or possibly needs to go to the silverstripe-s3 repo.

Steps to reproduce

  1. Create a clean install of SS4.x using the composer command -

        composer create-project silverstripe/installer /path/to/project 4.1.1
  2. Configure the site as normal and require silverstripe-s3

        composer require silverstripe/silverstripe-s3
  3. Complete configuration of S3

  4. Go to your site/admin and login

  5. Edit the Home Page- I get the following JS error -

    bundle.js?m=1520903238:1 Uncaught ReferenceError: tinymce is not defined
        at Object.create (bundle.js?m=1520903238:1)
        at Object.init (bundle.js?m=1520903238:1)
        at init.onadd (bundle.js?m=1520903238:1)
        at o (vendor.js?m=1520903238:1)
        at Array.<anonymous> (vendor.js?m=1520903238:1)
        at HTMLDocument.<anonymous> (vendor.js?m=1520903238:1)
        at HTMLDocument.dispatch (eval at t.exports (vendor.js?m=1520903238:1), <anonymous>:3332:9)
        at HTMLDocument.eventHandle (eval at t.exports (vendor.js?m=1520903238:1), <anonymous>:2941:28)
        at Object.trigger (eval at t.exports (vendor.js?m=1520903238:1), <anonymous>:3210:12)
        at init.triggerHandler (eval at t.exports (vendor.js?m=1520903238:1), <anonymous>:3874:24)

Screen shot - screen shot 2018-05-29 at 4 23 58 pm

I notice though that in my network console it is trying to load the tinymce script from the amazon public directory, not the local server address - example :

    ....s3.amazonaws.com/public/_tinymce/tinymce-cms-92563982d3.js?_=1527628916905 

vs /assets/tinymce/tinymce-cms-92563982d3.js?=1527628916905

Since this is loading the tinymce script file from S3 not sure if that is the cause of a race condition, cross domain origin issue or ?

If I refresh the page in the browser (eg /admin/pages/edit/show/1), the CMS loads normally and the WYSIWYG loads normally. If I go to a different section of the CMS besides pages though such as say 'Settings' and then back to pages I get the same issue until I reload the site.

Is this possibly an issue as the file is being generated into the /public/assets directory instead of the /public/resources directory? If there is a way to exclude this file from loading on S3 or a way to change the write path for the tinymce js I can test this some more to try and confirm what exactly is causing the issue.

Copied from original issue: silverstripe/silverstripe-cms#2177

kinglozzer commented 6 years ago

Migrated from https://github.com/silverstripe/silverstripe-cms/issues/2177. There’s a workaround available here https://github.com/silverstripe/silverstripe-cms/issues/2177#issuecomment-411688248

eehondas commented 6 years ago

Hi @kinglozzer , thanks for opening this. It is happening consistently for me as well on any given SS4 project. This is a sample composer extract

"require":{
        "php": ">=5.6.0",
        "silverstripe/cms": "^4.2",
        "silverstripe/framework": "^4.2",
        "silverstripe/recipe-plugin": "*",
        "silverstripe/recipe-cms": "*",
        "silverstripe/versioned": "1.*",
        "silverstripe/blog": "3.*",
        "silverstripe/widgets": "2.*",
        "silverstripe/userforms": "5.*",
        "silverstripe/redirectedurls": "2.*",
        "ryanpotter/silverstripe-cms-theme": "2.*",
        "undefinedoffset/sortablegridfield": "2.*",
        "silverstripe/staticpublishqueue": "4.*",
        "silverware/validator": "1.*",
        "unclecheese/display-logic": "2.*",
        "sheadawson/silverstripe-linkable": "2.*",
        "jonom/silverstripe-text-target-length": "2.*",
        "jonom/focuspoint": "3.*",
        "dnadesign/silverstripe-elemental": "3.0.x-dev",
        "axllent/silverstripe-cms-tweaks": "2.*",
        "heyday/silverstripe-menumanager": "~3.0.0",
        "heyday/silverstripe-colorpalette": "2.*"
  }

Unfortunately your proposed solution does not seem to fix the issue at all for me.

kinglozzer commented 6 years ago

@eehondas It doesn't look like you have the s3 module installed. If you’re experiencing that issue without using the s3 module, can you please post here instead: https://github.com/silverstripe/silverstripe-framework/issues/8228? Thanks :)

eehondas commented 6 years ago

@kinglozzer Yes. Done thank you. I just posted here because I followed from the other thread.

JoshuaCarter commented 5 years ago

Is there any movement on this? This is holding up a client upgrade for us. Cheers.

JoshuaCarter commented 5 years ago

Bump for great justice.

madmatt commented 5 years ago

Hey @JoshuaCarter, sorry for the delay - there's not a lot of support for this module as I'm not actively using it in production, and it was only ever meant as a proof-of-concept to test the new SS4 filesystem layer (I'm not entirely sure of the reasons why it was picked up under the silverstripe GitHub org :))

Anyway - have you been able to try the workaround that was posted by @kinglozzer here: https://github.com/silverstripe/silverstripe-cms/issues/2177#issuecomment-411688248? I'm keen to know if that still works for you or not, as it might help us assess where the problem lies.

I have a feeling it could be a race condition (TinyMCE file is written to S3 -> attempts to read immediately -> file can't be read -> file gets rewritten next request -> etc) but I haven't been able to confirm that as the cause yet. Theoretically the module shouldn't return an S3 URL unless the file was successfully replicated to S3 and exists in the S3 bucket (e.g. it should wait until the file is replicated within S3 before returning the URL) but perhaps we're missing something there.

obj63mc commented 5 years ago

@JoshuaCarter - I submitted a PR that has the workaround for this bug auto included (force tinymce files to write to the local filesystem). If you checkout the TinyMCEAdapter as well as the .yml file. If you implement that on your project you should have no issues.

madmatt commented 5 years ago

Hey @JoshuaCarter, I've just merged this in, so using the latest dev-master should resolve this for you now. Either @obj63mc or I will probably release a new version once #23 is merged.

madmatt commented 5 years ago

I've just released 0.4.0 that should hopefully resolve this for you!

Please let us know if you continue to have issues with this.