ember-fastboot / ember-cli-fastboot

Server-side rendering for Ember.js apps
http://ember-fastboot.com/
MIT License
851 stars 160 forks source link

Error with glimmer2 enabled with ember canary #255

Closed josemarluedke closed 8 years ago

josemarluedke commented 8 years ago

Per request from @rwjblue.

I tried to use ember-cli-fastboot (beta 8) with the latest ember canary with glimmer enabled by default and we get an error from this line.

My test app is at: https://github.com/josemarluedke/glimmer2-fastboot-try

The logs are:

2016-08-30T23:34:41.270Z 500 Unknown Error: TypeError: Cannot read property 'prototype' of undefined
    at Object.initialize (/Users/josemarluedke/Projects/OSS/josemarluedke/dist/fastboot/josemarluedke.js:189:31)
    at /Users/josemarluedke/Projects/OSS/josemarluedke/dist/fastboot/vendor.js:14752:23
    at /Users/josemarluedke/Projects/OSS/josemarluedke/dist/fastboot/vendor.js:14781:16
    at Object.visit [as default] (/Users/josemarluedke/Projects/OSS/josemarluedke/dist/fastboot/vendor.js:67273:5)
    at DAG.topsort (/Users/josemarluedke/Projects/OSS/josemarluedke/dist/fastboot/vendor.js:12786:23)
    at _emberRuntimeSystemNamespace.default.extend._runInitializer (/Users/josemarluedke/Projects/OSS/josemarluedke/dist/fastboot/vendor.js:14780:13)
    at _emberRuntimeSystemNamespace.default.extend.runInitializers (/Users/josemarluedke/Projects/OSS/josemarluedke/dist/fastboot/vendor.js:14741:12)
    at _emberApplicationSystemEngine.default.extend._bootSync (/Users/josemarluedke/Projects/OSS/josemarluedke/dist/fastboot/vendor.js:13918:14)
    at _emberApplicationSystemEngine.default.extend.boot (/Users/josemarluedke/Projects/OSS/josemarluedke/dist/fastboot/vendor.js:13885:14)
    at EmberApp.buildAppInstance (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/fastboot-express-middleware/node_modules/fastboot/src/ember-app.js:173:21)
    at EmberApp.visit (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/fastboot-express-middleware/node_modules/fastboot/src/ember-app.js:213:17)
    at FastBoot.visit (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/fastboot-express-middleware/node_modules/fastboot/src/index.js:70:22)
    at /Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/fastboot-express-middleware/index.js:32:14
    at Layer.handle [as handle_request] (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/layer.js:95:5)
    at /Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:271:10)
    at expressInit (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/middleware/init.js:33:5)
    at Layer.handle [as handle_request] (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:312:13)
    at /Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:271:10)
    at query (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/middleware/query.js:44:5)
    at Layer.handle [as handle_request] (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:312:13)
    at /Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:271:10)
    at Function.handle (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/router/index.js:176:3)
    at EventEmitter.handle (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/application.js:173:10)
    at Server.app (/Users/josemarluedke/Projects/OSS/josemarluedke/node_modules/ember-cli-fastboot/node_modules/express/lib/express.js:38:9)
    at emitTwo (events.js:106:13)
    at Server.emit (events.js:191:7)
    at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:543:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:105:23)
rwjblue commented 8 years ago

Thanks for testing this out! I believe we need to detect if these monkey patches are needed and simply do nothing if they are not.

I do not think the DOMHelper monkey patch is needed for 2.7+ of Ember (though @tomdale and/or @ronco may need to confirm the exact version).

tomdale commented 8 years ago

@rwjblue Where does the behavior that is being monkeypatched by FastBoot live now?

bantic commented 8 years ago

The two monkeypatches are protocolForUrl and parseHTML.

prototcolForUrl is now in ember-glimmer/lib/protocol-for-url.js, and appears to be Fastboot/Node-compatible.

I'm not sure where parseHTML is called, but I don't see a replacement for it in the ember.js codebase.

cc @tomdale

tomdale commented 8 years ago

@bantic parseHTML is used when you have unescaped dynamic values aka {{{triple-curlies}}}. In the browser we parse the HTML and insert the resulting fragment into the DOM as-is. In FastBoot, we use a non-standard SimpleDOM API for adding "raw" HTML that just gets serialized out directly without an intermediate parsing step.

@chancancode @chadhietala Is the plan of record to maintain a Node-compatible DOMHelper in Glimmer? If so, I think we can safely remove this monkeypatch for newer versions.

chancancode commented 8 years ago

@tomdale yes

rwjblue commented 8 years ago

@chancancode @chadhietala Is the plan of record to maintain a Node-compatible DOMHelper in Glimmer? If so, I think we can safely remove this monkeypatch for newer versions.

Yes, that is what I was trying to say in https://github.com/ember-fastboot/ember-cli-fastboot/issues/255#issuecomment-243615562:

I believe we need to detect if these monkey patches are needed and simply do nothing if they are not.