{"action":"created","issue":{"url":"https://api.github.com/repos/lift/framework/issues/1711","labels_url":"https://api.github.com/repos/lift/framework/issues/1711/labels{/name}","comments_url":"https://api.github.com/repos/lift/framework/issues/1711/comments","events_url":"https://api.github.com/repos/lift/framework/issues/1711/events","html_url":"https://github.com/lift/framework/pull/1711","id":94631035,"number":1711,"title":"High Wire: Fix appendJs when invoked from inside a toJsCmd def","user":{"login":"Shadowfiend","id":8245,"avatar_url":"https://avatars.githubusercontent.com/u/8245?v=3","gravatar_id":"","url":"https://api.github.com/users/Shadowfiend","html_url":"https://github.com/Shadowfiend","followers_url":"https://api.github.com/users/Shadowfiend/followers","following_url":"https://api.github.com/users/Shadowfiend/following{/other_user}","gists_url":"https://api.github.com/users/Shadowfiend/gists{/gist_id}","starred_url":"https://api.github.com/users/Shadowfiend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shadowfiend/subscriptions","organizations_url":"https://api.github.com/users/Shadowfiend/orgs","repos_url":"https://api.github.com/users/Shadowfiend/repos","events_url":"https://api.github.com/users/Shadowfiend/events{/privacy}","received_events_url":"https://api.github.com/users/Shadowfiend/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-13T03:40:23Z","updated_at":"2015-07-13T11:03:56Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/lift/framework/pulls/1711","html_url":"https://github.com/lift/framework/pull/1711","diff_url":"https://github.com/lift/framework/pull/1711.diff","patch_url":"https://github.com/lift/framework/pull/1711.patch"},"body":"This fixes #1708 specifically.\r\n\r\n`appendJs` should append JavaScript to be sent down with the\r\ncurrent request. However, if `appendJs` is called in a `toJsCmd`\r\nmethod, and that method is defined as a `def`, not a `val`, then\r\n`toJsCmd` will be called *after* the `jsToAppend` is read. This\r\nmeans that this appended JS won't be sent down.\r\n\r\nOne place where this manifests is when a `JsCmd`'s `toJsCmd`\r\nmethod sends down a rendered snippet that contains a Wiring\r\ncomponent (because Wiring uses `appendJs`). In this case, the\r\n`appendJs` that Wiring does is evaluated during the `toJsCmd`\r\ninvocation, which means the JsCmd that is sent down misses it.\r\n\r\nWhen we send down JS in bulk for an AJAX or comet response,\r\nwe wrap it in a `JsCommands`, which is a collector of `JsCmd`.\r\nWe then call its `toResponse` to get a `JavaScriptResponse`.\r\n\r\nBefore, we passed the `jsToAppend` to `JsCommands`, and then\r\nlet `JsCommands` run `toJsCmd` on everyone while constructing\r\nthe response. In this PR, let the `toResponse` method call `toJsCmd`\r\non all the commands that are explicitly being sent down, and then\r\nwe read `jsToAppend` and concatenate that on the end of the other\r\ncommands inside `toResponse`. In the process, we remove external\r\ninvocations of `jsToAppend`.\r\n\r\nSo as to avoid accidental duplicate send-downs of `jsToAppend`, we\r\ngive `jsToAppend` a `clearAfterReading` boolean that, when set to\r\n`true` (it defaults to `false`), will clear the list of `JsCmd`s that need\r\nto be appended. `JsCommands` and the `jsToAppend` reading in\r\n`CometActor`, which sends down additional JS as a partial update,\r\nboth set it to `true`. Amongst other things, this ensures the two won't\r\nboth try to send down the same JS.\r\n\r\nStill pending here: I (or someone else) need to test some of the\r\nscenarios of `appendJs`, like calling it from inside a comet, from\r\na regular AJAX request, and from a regular screen render."},"comment":{"url":"https://api.github.com/repos/lift/framework/issues/comments/120891232","html_url":"https://github.com/lift/framework/pull/1711#issuecomment-120891232","issue_url":"https://api.github.com/repos/lift/framework/issues/1711","id":120891232,"user":{"login":"andreak","id":321577,"avatar_url":"https://avatars.githubusercontent.com/u/321577?v=3","gravatar_id":"","url":"https://api.github.com/users/andreak","html_url":"https://github.com/andreak","followers_url":"https://api.github.com/users/andreak/followers","following_url":"https://api.github.com/users/andreak/following{/other_user}","gists_url":"https://api.github.com/users/andreak/gists{/gist_id}","starred_url":"https://api.github.com/users/andreak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreak/subscriptions","organizations_url":"https://api.github.com/users/andreak/orgs","repos_url":"https://api.github.com/users/andreak/repos","events_url":"https://api.github.com/users/andreak/events{/privacy}","received_events_url":"https://api.github.com/users/andreak/received_events","type":"User","site_admin":false},"created_at":"2015-07-13T11:03:56Z","updated_at":"2015-07-13T11:03:56Z","body":"It seems the contextPath-issue only manifests it self when the JS-content is generated in another thread (job on thread-pool), not having access to Req of Session. Forget about this for now..."}}