# Steal refuses to load TinyMCE

**URL:** <https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217>\
**Category:** StealJS\
**Created:** [April 6, 2016, 8:13pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217 "2016-04-06T20:13:08Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)\
**Post date:** [April 7, 2016, 2:36pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217/21 "2016-04-07T14:36:23Z")

</div>

File a bug in done-ssr about document.location. I didn’t know such a property exists. We already set `window.location` so we can do the same for document.location.

But it’s entirely possible that this module can’t be loaded by our virtual dom. if that’s the case you should turn it off in Node like so:

```json
{
  "system": {
    "envs": {
      "server-development": {
        "map": {
          "tinymce/tinymce": "@empty"
        }
      },
      "server-production": { same as above }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)\
**Post date:** [April 7, 2016, 2:36pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217/22 "2016-04-07T14:36:32Z")

</div>

Ah, ok. This has nothing to do with steal. It has everything to do w/ the very simple DOM (can-simple-dom) we use to render our site. `window.location.href` exists, but not `document.location.href`.

There are three possible solutions:

1. Ask @matthewp on how you could swap to something like JSDom instead of `can-simple-dom` that might support what’s needed to load tinymce.
2. Add `document.location.href` to `can-simple-dom` (or find a plugin that can do that).
3. Make it so tinymce is not run server-side. [https://donejs.com/bitballs.html#section=section\_TurnoffSSR](https://donejs.com/bitballs.html#section=section_TurnoffSSR)

#3 is the easiest, but might not be satisfactory depending on what you want your users to see.

---

<div class="post-metadata">

**Author:** ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)\
**Post date:** [April 7, 2016, 2:40pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217/23 "2016-04-07T14:40:32Z")

</div>

Regarding preventing tinymce from running server-side, the bitballs solution wont work here. You’d have to use @matthewp’s solution.

This is because the module itself seems like it is looking for `document.location.href`, not initialization of some export of the module.

What that means is that a module that looks like:

```
require("jquery")
document.location.href

```

will break and require matthew’s `"empty"` method.

But if it was written like:

```
require("jquery");
module.exports = function(){ document.location.href }

```

It could use the bitballs way of doing it.

---

<div class="post-metadata">

**Author:** ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)\
**Post date:** [April 7, 2016, 2:43pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217/24 "2016-04-07T14:43:38Z")

</div>

I’m going to create a demo real quick and see if setting document.location will do the trick.

---

<div class="post-metadata">

**Author:** ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)\
**Post date:** [April 7, 2016, 3:16pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217/25 "2016-04-07T15:16:30Z")

</div>

Ok, I was able to get it to load locally by making the follow changes:

1. After this line: [https://github.com/canjs/canjs/blob/master/util/vdom/vdom.js#L6](https://github.com/canjs/canjs/blob/master/util/vdom/vdom.js#L6) I added:

- `global.document.location = {href:"/"};`

1. After this line: [https://github.com/canjs/can-simple-dom/blob/master/lib/simple-dom/document.js#L102](https://github.com/canjs/can-simple-dom/blob/master/lib/simple-dom/document.js#L102) I added

- `first.src = "";`

And it was able to load. However this is _before trying to use it_ so it’s hard telling what is required when you want to start displaying stuff.

So I would probably go with the map to `@empty` method. Note that for this to work your app that actually imports the module should detect if it’s running in Node like:

```auto
import tinymce from "tinymce/tinymce";
import platform from "steal-platform";

if(platform.isNode) {
  // tinymce is undefined
} else {
  // Use tinymce
}

```

---

<div class="post-metadata">

**Author:** ![tracer99](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/tracer99/32/35_2.png) [@tracer99](https://forums.bitovi.com/u/tracer99)\
**Post date:** [April 7, 2016, 4:05pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217/26 "2016-04-07T16:05:36Z")

</div>

You asked me to file a bug with done-ssr, do you still want this?

---

<div class="post-metadata">

**Author:** ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)\
**Post date:** [April 7, 2016, 4:51pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217/27 "2016-04-07T16:51:26Z")

</div>

A better way I think would be to do:

```
if(tinymce) {
  // tinymce is undefined
} else {
  // Use tinymce
}
```

---

<div class="post-metadata">

**Author:** ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)\
**Post date:** [April 7, 2016, 5:58pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217/28 "2016-04-07T17:58:07Z")

</div>

You can file a bug with canjs / can-simple-dom about those two changes I needed to do. Not sure what is the “correct” fix, but good to think about.

---

<div class="post-metadata">

**Author:** ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)\
**Post date:** [April 7, 2016, 5:58pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217/29 "2016-04-07T17:58:40Z")

</div>

I like the other way slightly better because it’s explicit, checking if tinymce is undefined doesn’t explain why it is undefined.

---

<div class="post-metadata">

**Author:** ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)\
**Post date:** [April 7, 2016, 6:05pm UTC](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217/30 "2016-04-07T18:05:19Z")

</div>

> [@matthewp](#):
>
> if(platform.isNode) {

I don’t like `if(platform.isNode) {` mostly because it will be true for NW.js

[Previous page](https://forums.bitovi.com/t/steal-refuses-to-load-tinymce/217.md?page=1)
