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

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

Closed
obj63mc opened this issue May 29, 2018 · 21 comments

Comments

@obj63mc
Copy link

obj63mc commented May 29, 2018

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.

@obj63mc obj63mc changed the title SilverStripe 4.1.x and Silverstripe S3 - TinyMCE WYSIWYG doesn't load on initial CMS Load SilverStripe 4.1.x and Silverstripe-S3 module - TinyMCE WYSIWYG doesn't load on initial CMS Load May 29, 2018
@maxime-rainville
Copy link
Contributor

The silverstripe/s3 module is experimental. It's not something we're actively working on at this time.

@obj63mc
Copy link
Author

obj63mc commented Jul 13, 2018

As a note, I turned off and removed the S3 module and still have the same issue. So not 100% sure it is caused by that module.

When trying to determine the cause of this. My site is setup with the following -

  1. the 'mysite' code lives in the 'app' folder in the root. I have a structure that is based off of - https://github.com/a2nt/silverstripe-webpack

  2. The following modules are installed -

         aws/aws-sdk-php                            3.62.11           
         colymba/gridfield-bulk-editing-tools       3.0.0-beta4       
         composer/ca-bundle                         1.1.1             
         composer/installers                        v1.5.0            
         dnadesign/silverstripe-elemental           2.1.0             
         dnadesign/silverstripe-elemental-list      1.0.0             
         dnadesign/silverstripe-elemental-userforms 1.0.0             
         dnadesign/silverstripe-elemental-virtual   dev-master 3867957
         doctrine/instantiator                      1.1.0             
         embed/embed                                v3.3.5            
         guzzlehttp/guzzle                          6.3.3             
         guzzlehttp/promises                        v1.3.1            
         guzzlehttp/psr7                            1.4.2             
         intervention/image                         2.4.2             
         jonom/silverstripe-betternavigator         4.1.1             
         league/flysystem                           1.0.45            
         league/flysystem-aws-s3-v3                 1.0.19            
         m1/env                                     2.1.2             
         marcj/topsort                              1.1.0             
         monolog/monolog                            1.23.0            
         moosylvania/silverstripe-age-gate          2.1.0             
         mtdowling/jmespath.php                     2.4.0             
         myclabs/deep-copy                          1.8.1             
         nikic/php-parser                           v3.1.5            
         paragonie/random_compat                    v2.0.17           
         phpdocumentor/reflection-common            1.0.1             
         phpdocumentor/reflection-docblock          4.3.0             
         phpdocumentor/type-resolver                0.4.0             
         phpspec/prophecy                           1.7.6             
         phpunit/php-code-coverage                  4.0.8             
         phpunit/php-file-iterator                  1.4.5             
         phpunit/php-text-template                  1.2.1             
         phpunit/php-timer                          1.0.9             
         phpunit/php-token-stream                   2.0.2             
         phpunit/phpunit                            5.7.27            
         phpunit/phpunit-mock-objects               3.4.4             
         psr/cache                                  1.0.1             
         psr/container                              1.0.0             
         psr/http-message                           1.0.1             
         psr/log                                    1.0.2             
         psr/simple-cache                           1.0.1             
         sebastian/code-unit-reverse-lookup         1.0.1             
         sebastian/comparator                       1.2.4             
         sebastian/diff                             1.4.3             
         sebastian/environment                      2.0.0             
         sebastian/exporter                         2.0.0             
         sebastian/global-state                     1.1.1             
         sebastian/object-enumerator                2.0.1             
         sebastian/recursion-context                2.0.0             
         sebastian/resource-operations              1.0.0             
         sebastian/version                          2.0.1             
         sheadawson/silverstripe-linkable           2.0.0             
         silverstripe/admin                         1.1.2             
         silverstripe/asset-admin                   1.1.2             
         silverstripe/assets                        1.1.2             
         silverstripe/blog                          3.2.0             
         silverstripe/campaign-admin                1.1.2             
         silverstripe/cms                           4.1.2             
         silverstripe/comment-notifications         2.0.1             
         silverstripe/comments                      3.1.2             
         silverstripe/config                        1.0.4             
         silverstripe/elemental-blocks              1.0.0             
         silverstripe/errorpage                     1.1.2             
         silverstripe/externallinks                 2.0.2             
         silverstripe/framework                     4.1.2             
         silverstripe/graphql                       1.1.2             
         silverstripe/html5                         2.0.1             
         silverstripe/lumberjack                    2.0.0             
         silverstripe/recaptcha                     dev-master 6c839da
         silverstripe/recipe-cms                    1.1.2             
         silverstripe/recipe-core                   1.1.2             
         silverstripe/recipe-plugin                 1.3.0             
         silverstripe/redirectedurls                2.0.0             
         silverstripe/reports                       4.1.2                      
         silverstripe/segment-field                 2.2.1             
         silverstripe/siteconfig                    4.1.2             
         silverstripe/spamprotection                3.0.0             
         silverstripe/tagfield                      2.1.0             
         silverstripe/userforms                     5.2.0             
         silverstripe/vendor-plugin                 1.3.3             
         silverstripe/versioned                     1.1.2             
         swiftmailer/swiftmailer                    v5.4.9            
         symbiote/silverstripe-gridfieldextensions  3.2.0             
         symfony/cache                              v3.4.12           
         symfony/config                             v3.4.12           
         symfony/filesystem                         v4.1.1            
         symfony/finder                             v3.4.12           
         symfony/polyfill-apcu                      v1.8.0            
         symfony/polyfill-ctype                     v1.8.0            
         symfony/polyfill-mbstring                  v1.8.0            
         symfony/translation                        v2.8.42           
         symfony/yaml                               v3.4.12           
         unclecheese/display-logic                  2.0.1             
         undefinedoffset/sortablegridfield          2.0.6             
         webmozart/assert                           1.3.0             
         webonyx/graphql-php                        v0.8.0            
         wilr/silverstripe-googlesitemaps           2.1.2             
    

When referencing silverstripe/silverstripe-framework#8228 it seems like it may be because we are both using webpack for our front end code, but can't say if that is the cause or not either. I am in the process of doing a clean install and changing each step to replicate my previous site to see where it breaks.

@anishpixel
Copy link

I am having the same issue, I am using webpack for my web build too so think something is conflicting.

@spark-green
Copy link

spark-green commented Jul 31, 2018

Hi guys,
I am having the same issue,
I am not using S3 module. but using webpack to run foundation on front-end.

And surprising it is happening only with one single page in CMS.
screenshot

image

Console error as below
image

For reference I am using below version of silver-stripe and other modules

"php": ">=5.6.0",
"silverstripe/cms": "4.1.1",
"silverstripe/framework": "4.1.1",
"silverstripe/recipe-plugin": "^1",
"silverstripe/recipe-cms": "1.",
"silverstripe/versioned": "1.
",
"silverstripe/blog": "3.",
"silverstripe/widgets": "2.
",
"ryanpotter/silverstripe-cms-theme": "2.",
"undefinedoffset/sortablegridfield": "2.
",
"silverstripe/staticpublishqueue": "4.",
"jonom/focuspoint": "dev-master",
"unclecheese/display-logic": "2.
",
"sheadawson/silverstripe-linkable": "2.",
"silverware/validator": "1.
",
"jonom/silverstripe-text-target-length": "2.",
"axllent/silverstripe-cms-tweaks": "2.
",
"symbiote/silverstripe-gridfieldextensions": "^3.0"

Any help on this is much appreciated.

@806software
Copy link

Also experiencing similar issue. However, I am using the S3 module, and not using Webpack. The TinyMCE script is being loaded from S3.

Just currently trying to work out why that is placed into assets when all other admin JS isn't

@anishpixel
Copy link

No reply from SS mods or contributors? Seems odd to avoid this as various people are having this issue...

@806software
Copy link

806software commented Aug 8, 2018

It looks to be a timing thing. The script tinymce-cms-<unique-string>.js is actually loaded from S3, but I am guessing it is after it is actually called. I assume that is why if the page is reloaded, it appears to work as it is now already in the cache. However going back some time later, it is requested again but with a cache busting parameter.

I can see why it is generated as it references the site domain to setup a baseUrl var, also based on a specific configuration of the editor.

Just wondering what can be done about that.

Not totally sure if this fits in with everyone else's experience if not using the S3 module.

@806software
Copy link

When reloading, the requirements system places the call for the script into the page source, as you would expect, therefore I assume everything blocks until all the scripts have loaded, and everything works.

Navigating within the CMS, when you move to an area that requires the TinyMCE editor, the JavaScript requirements are pulled in via Ajax and anx-include-js header. I assume there is some timing issue here between the script being requested and the editor trying to load, but before the script has loaded in, hence the tinymce is not defined error.

Is there any way of forcing the request for the TinyMCE script earlier, or delaying the editor from trying to initialise for a bit longer?

@806software
Copy link

Is there a way to configure the Requirements system to place the TinyMCE generated file to a local folder? There is some information on requirements about changing where combined assets are placed, but so far not making any headway with that.

@kinglozzer
Copy link
Member

@JPMCC The behaviour of x-include-js is the same without the S3 module installed, so provided the request to the tinymce-cms.js is returning a valid response I can’t see why it would result in a race condition or anything. It’s not being blocked by CORS headers or something is it?

@806software
Copy link

806software commented Aug 8, 2018

No idea. I can see the file contents are loaded by the browser, but obviously too late to prevent the undefined error.

I was just wondering if there was a way to override the tinymce file being placed in assets, but elsewhere - by using the method outlined int he requirements documentation. I know that kind of defeats the purpose of having assets somewhere like S3, but just clutching at straws at the moment.

@kinglozzer
Copy link
Member

You might be able to override the asset handler for TinyMCE generated files. Totally untested code below, but it might provide a starting point:

SilverStripe\Core\Injector\Injector:
  League\Flysystem\Filesystem.localpublic:
    class: League\Flysystem\Filesystem
    constructor:
      FilesystemAdapter: '%$SilverStripe\Assets\Flysystem\PublicAssetAdapter'
      FilesystemConfig:
        visibility: public
  LocalGeneratedAssetHandler:
    class: SilverStripe\Assets\Flysystem\GeneratedAssets
    properties:
      Filesystem: '%$League\Flysystem\Filesystem.localpublic'
  SilverStripe\Forms\HTMLEditor\TinyMCECombinedGenerator:
    properties:
      AssetHandler: '%$LocalGeneratedAssetHandler'

@806software
Copy link

Thanks Loz, I think I was going down the same path based on the docs, but I think I'm still missing something. The GeneratedAssetHandler being injected into the TinyMCE generator still uses the SilverStripe\S3\Adapter\PublicCacheAdapter as the Adaptor.

@806software
Copy link

Not sure the configuration is even being picked up :-(. Created a yml file in the _config folder. I would expect to see an instance of League\Flysystem\Filesystem being created. The only one that triggers the constructor is for the S3 adapter.

Therefore I'm assuming I am missing something pretty fundamental. All my other yml files appear to be processed (multiple builds and flushes).

@kinglozzer
Copy link
Member

Maybe you need a YAML header to ensure it’s loaded last

---
After:
  - '#corehtml'
---
SilverStripe\Core\Injector\Injector:
  League\Flysystem\Filesystem.localpublic:
# ...

@806software
Copy link

yup, using

---
Name: tinymce_override
After:
  - '#silverstripes3-flysystem'
---

I'll try #corehtml

@806software
Copy link

806software commented Aug 9, 2018

No luck.

Really appreciate the help :). I may have to come back to this later.

@kinglozzer
Copy link
Member

The following does seem to work in my testing - App\TestAssetAdapter is the adapter used in TinyMCECombinedGenerator:

---
After:
  - '#corehtml'
---
SilverStripe\Core\Injector\Injector:
  League\Flysystem\Filesystem.localpublic:
    class: 'League\Flysystem\Filesystem'
    constructor:
      FilesystemAdapter: '%$App\TestAssetAdapter'
      FilesystemConfig:
        visibility: public
  LocalGeneratedAssetHandler:
    class: 'SilverStripe\Assets\Flysystem\GeneratedAssets'
    properties:
      Filesystem: '%$League\Flysystem\Filesystem.localpublic'
  SilverStripe\Forms\HTMLEditor\TinyMCECombinedGenerator:
    properties:
      AssetHandler: '%$LocalGeneratedAssetHandler'
namespace App;

use SilverStripe\Assets\Flysystem\PublicAssetAdapter;

class TestAssetAdapter extends PublicAssetAdapter
{
}

Probably best at this point to hop on the forums or Slack to save adding any more to this issue 😄

@kinglozzer
Copy link
Member

@JPMCC has confirmed that the above will allow the TinyMCE JS to be written to the local filesystem rather than S3, which offers a workaround for the issue for now.

As this definitely occurs with the S3 module installed, I’m going to move this issue to that repo. Even if it requires a fix in framework, it’s best to track the issue there as that module seems to be the only definite cause.

For those experiencing this issue without S3 installed (@spark-green, @anishpixel?) I’m going to re-open silverstripe/silverstripe-framework#8228 as there’s less S3-related noise there. If you’re still experiencing this issue, please paste the output of composer show into that issue so we know which exact versions of each module you’re using. Thanks!

@kinglozzer
Copy link
Member

This issue was moved to silverstripe/silverstripe-s3#18

@lekoala
Copy link
Contributor

lekoala commented Feb 25, 2021

I found this issue when having the same error. in my case it's not linked to s3

silverstripe/silverstripe-admin#996

so if it helps anyone ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants