{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Blazor/issues/552","repository_url":"https://api.github.com/repos/aspnet/Blazor","labels_url":"https://api.github.com/repos/aspnet/Blazor/issues/552/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Blazor/issues/552/comments","events_url":"https://api.github.com/repos/aspnet/Blazor/issues/552/events","html_url":"https://github.com/aspnet/Blazor/issues/552","id":313621208,"node_id":"MDU6SXNzdWUzMTM2MjEyMDg=","number":552,"title":"Add compiler error if there's a <script> element inside a component","user":{"login":"SteveSandersonMS","id":1101362,"node_id":"MDQ6VXNlcjExMDEzNjI=","avatar_url":"https://avatars3.githubusercontent.com/u/1101362?v=4","gravatar_id":"","url":"https://api.github.com/users/SteveSandersonMS","html_url":"https://github.com/SteveSandersonMS","followers_url":"https://api.github.com/users/SteveSandersonMS/followers","following_url":"https://api.github.com/users/SteveSandersonMS/following{/other_user}","gists_url":"https://api.github.com/users/SteveSandersonMS/gists{/gist_id}","starred_url":"https://api.github.com/users/SteveSandersonMS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SteveSandersonMS/subscriptions","organizations_url":"https://api.github.com/users/SteveSandersonMS/orgs","repos_url":"https://api.github.com/users/SteveSandersonMS/repos","events_url":"https://api.github.com/users/SteveSandersonMS/events{/privacy}","received_events_url":"https://api.github.com/users/SteveSandersonMS/received_events","type":"User","site_admin":false},"labels":[{"id":794119641,"node_id":"MDU6TGFiZWw3OTQxMTk2NDE=","url":"https://api.github.com/repos/aspnet/Blazor/labels/3%20-%20Done","name":"3 - Done","color":"cccccc","default":false},{"id":794118845,"node_id":"MDU6TGFiZWw3OTQxMTg4NDU=","url":"https://api.github.com/repos/aspnet/Blazor/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/aspnet/Blazor/milestones/5","html_url":"https://github.com/aspnet/Blazor/milestone/5","labels_url":"https://api.github.com/repos/aspnet/Blazor/milestones/5/labels","id":3212992,"node_id":"MDk6TWlsZXN0b25lMzIxMjk5Mg==","number":5,"title":"0.2.0","description":"","creator":{"login":"danroth27","id":1874516,"node_id":"MDQ6VXNlcjE4NzQ1MTY=","avatar_url":"https://avatars2.githubusercontent.com/u/1874516?v=4","gravatar_id":"","url":"https://api.github.com/users/danroth27","html_url":"https://github.com/danroth27","followers_url":"https://api.github.com/users/danroth27/followers","following_url":"https://api.github.com/users/danroth27/following{/other_user}","gists_url":"https://api.github.com/users/danroth27/gists{/gist_id}","starred_url":"https://api.github.com/users/danroth27/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danroth27/subscriptions","organizations_url":"https://api.github.com/users/danroth27/orgs","repos_url":"https://api.github.com/users/danroth27/repos","events_url":"https://api.github.com/users/danroth27/events{/privacy}","received_events_url":"https://api.github.com/users/danroth27/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":29,"state":"closed","created_at":"2018-03-23T18:12:22Z","updated_at":"2018-04-20T23:49:34Z","due_on":"2018-04-16T07:00:00Z","closed_at":"2018-04-18T16:23:55Z"},"comments":12,"created_at":"2018-04-12T08:14:57Z","updated_at":"2018-07-21T11:31:46Z","closed_at":"2018-04-12T15:28:34Z","author_association":"MEMBER","body":"This addresses a usability issue. We often hear of people trying to put `<script>` elements inside components and being surprised about the effects.\r\n\r\nIt's almost always a mistake to put a `<script>` element inside a component, because fundamentally, components are about adding and removing things dynamically inside the DOM. `<script>` elements don't work that way, in that once they are added, their effects can never be removed. Similarly, trying to use C# expressions inside a `<script>` content will not work as expected (we can't replace the effects of already-registered JS once the expression changes value). The *only* scenario I can think of where a `<script>` element does something vaguely useful inside a component would be for some kind of debug logging, e.g., `<script>console.log('rendering now')</script>`, but that's not what anyone's been doing AFAIK. What developers really should do is put `<script>` elements into their `index.html`, where they will behave as expected.\r\n\r\n**Proposed solution**\r\n\r\nWe'll make it a compiler error to have `<script>` inside a Blazor component. The error message will say something like:\r\n\r\n*Script tags should not be placed inside components because they cannot be updated dynamically. To fix this, move the script tag to the 'index.html' file or another static location. For more information see http://some/link*\r\n\r\n... and the help docs that we linked to will also say something like:\r\n\r\n*If you need to override this, add an attribute named \"suppress-error\" with value \"BL9992\" to the <script> tag, but only if you know what you are doing, as in most cases it would be a mistake to do this*."},"comment":{"url":"https://api.github.com/repos/aspnet/Blazor/issues/comments/406789476","html_url":"https://github.com/aspnet/Blazor/issues/552#issuecomment-406789476","issue_url":"https://api.github.com/repos/aspnet/Blazor/issues/552","id":406789476,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjc4OTQ3Ng==","user":{"login":"lakani","id":9746768,"node_id":"MDQ6VXNlcjk3NDY3Njg=","avatar_url":"https://avatars2.githubusercontent.com/u/9746768?v=4","gravatar_id":"","url":"https://api.github.com/users/lakani","html_url":"https://github.com/lakani","followers_url":"https://api.github.com/users/lakani/followers","following_url":"https://api.github.com/users/lakani/following{/other_user}","gists_url":"https://api.github.com/users/lakani/gists{/gist_id}","starred_url":"https://api.github.com/users/lakani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lakani/subscriptions","organizations_url":"https://api.github.com/users/lakani/orgs","repos_url":"https://api.github.com/users/lakani/repos","events_url":"https://api.github.com/users/lakani/events{/privacy}","received_events_url":"https://api.github.com/users/lakani/received_events","type":"User","site_admin":false},"created_at":"2018-07-21T11:31:46Z","updated_at":"2018-07-21T11:31:46Z","author_association":"NONE","body":"i'm trying this, but its not working with me , am i missing something ???\r\n\r\nmy \\wwwroot\\index.html\r\n\r\n`<script type=\"blazor-boot\">\r\n        \r\n    // Register a very simple JavaScript function that just prints\r\n    // the input parameter to the browser's console\r\n    Blazor.registerFunction('say', (data) => {\r\n        console.dir(data);\r\n\r\n        // Your function currently has to return something. For demo\r\n        // purposes, we just return `true`.\r\n        return true;\r\n    });\r\n\r\n    </script>`\r\n\r\n\r\nand my \\Pages\\FetchData.cshtml\r\n\r\n`<button onclick=@CallJS>Call JavaScript</button>\r\n\r\n@functions {\r\nWeatherForecast[] forecasts;\r\n\r\n\r\nprivate async void CallJS()\r\n{\r\n    // Simple function call with a basic data type\r\n    if (RegisteredFunction.Invoke<bool>(\"say\", \"Hello\"))\r\n    {\r\n        // This line will be reached as our `say` function returns true\r\n        Console.WriteLine(\"Returned true\");\r\n    }\r\n\r\n    // Call our function with an object. It will be serialized (JSON),\r\n    // passed to JS-part of Blazor and deserialized into a JavaScript\r\n    // object again.\r\n    RegisteredFunction.Invoke<bool>(\"say\", new { greeting = \"Hello\" });\r\n\r\n    // Get some demo data from a web service and pass it to our function.\r\n    // Again, it will be turned to JSON and back during the function call.\r\n    //var customers = await Http.GetJsonAsync<List<Customer>>(\"/api/Customer\");\r\n    //RegisteredFunction.Invoke<bool>(\"say\", customers);\r\n}\r\n`\r\n\r\n"}}
{"actor":{"display_login":"lakani"}}