Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React is failing with script tags. #3649

Closed
trusktr opened this issue Apr 11, 2015 · 3 comments
Closed

React is failing with script tags. #3649

trusktr opened this issue Apr 11, 2015 · 3 comments

Comments

@trusktr
Copy link

trusktr commented Apr 11, 2015

React is not liking this:

    render: function() {
        return (
            <div class="gl-map-container">

                <script id="shader-fs" type="x-shader/x-fragment">
                    precision mediump float;

                    void main(void) {
                        gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
                    }
                </script>

                <script id="shader-vs" type="x-shader/x-vertex">
                    attribute vec3 aVertexPosition;

                    uniform mat4 uMVMatrix;
                    uniform mat4 uPMatrix;

                    void main(void) {
                        gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
                    }
                </script>

                <canvas width='500' height='500' className="gl-map-canvas">
                </canvas>
            </div>
        );
    }

What's the workaround?

@sophiebits
Copy link
Collaborator

Can you be more specific? What did you expect to happen? What happened instead?

@zpao
Copy link
Member

zpao commented Apr 11, 2015

You probably want this. But even so, your script probably won't execute (most browsers won't execute scripts when innerHTMLed.

<script dangerouslySetInnerHTML={{__html: `
  alert();
`}} />

@trusktr
Copy link
Author

trusktr commented Apr 11, 2015

Sweet, that would work! It's type="x-shader/x-vertex", etc, so the browser isn't supposed to read it anyways. I can grab it later (componentDidMount) to compile the shaders. Ironically, I ended up just using template strings outside of the JSX, which ends up having syntax highlight in Vim, so even better.

@trusktr trusktr closed this as completed Apr 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants