Skip to content

<script> isn’t executed if created by react-basic-hooks #76

@Hi-Angel

Description

@Hi-Angel

From what I found on JS behavior this isn't expected behavior, usually inserting <script> does execute it.

I searched over Props_script for something like "enableExecution" but found nothing. I don't suppose this is expected to happen.

Steps to reproduce

  1. Create new project with spago init
  2. Create index.html as
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" href="styles.css">
    </head>
    <body>
      <div id="root"></div>
      <script src="index.js"></script>
    </body>
    </html>
  3. Put this code to src/Main.purs
    module Main where
    
    import Prelude
    
    import Data.Maybe (Maybe(..))
    import Effect (Effect)
    import Effect.Exception (throw)
    import React.Basic.DOM as R
    import React.Basic.DOM.Client (createRoot, renderRoot)
    import React.Basic.Hooks (Component, component)
    import Web.DOM.NonElementParentNode (getElementById)
    import Web.HTML (window)
    import Web.HTML.HTMLDocument (toNonElementParentNode)
    import Web.HTML.Window (document)
    
    main :: Effect Unit
    main = do
      doc <- document =<< window
      root <- getElementById "root" $ toNonElementParentNode doc
      case root of
        Nothing -> throw "Could not find root."
        Just container -> do
          reactRoot <- createRoot container
          app <- myComponent
          renderRoot reactRoot (app {})
    
    myComponent :: Component {}
    myComponent =
      component "Test" \_ -> React.do
        pure $ R.script {children: [R.text "alert(1)"]}
  4. Install deps as spago install console effect exceptions maybe prelude react-basic react-basic-dom react-basic-hooks web-dom web-html
  5. Build it with spago bundle-app
  6. Open index.html in a browser

Expected

An alert should pop up

Actual

No popups appear

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions