-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
DOM body's first div is used, but could be used by browser extension #339
Comments
Interesting - I don't think we can force people to render into a container, but we can definitely have SSR mark the rendered app's root node and give that preference over |
I thought that when using a template, Preact would render to a specific element. Isn't that the case ? I think preact-cli init is missing one example using an html file (equivalent to Create-React-App public/index.html). Also, IMHO, some of the functionality in @zouhir preact-habitat should be part of preact-cli, to make it really easy to use any preact component on any html page |
Why not have public/index.html like with CRA and always render to a given div ? |
We are not exposing the index.html file but you can pass your template to the In this you can do any sort of modifications which you want to the HTML file 😄 |
Yes, I mention template in my first comment, but my second comment is more focused on the current issue, on a specific way to solve it. |
I guess it works this way because no one expects that the DOM is manipulated by anything other than Preact, so Sure, this could probably be fixed by introducing a |
I think if we inject a root ID/attribute during SSR (by post-processing the rendered HTML) we can make this nice and transparent. // during SSR:
let bodyHtml = render( .. );
bodyHtml = bodyHtml.replace(/^(<[a-z][a-z0-9:-]*)/i, '$1 data-preact-root'); ... then on the client: let root = document.querySelector('[data-preact-root]') || document.body.firstElementChild;
render(<App />, root.parentNode || document.body, root); |
Do you want to request a feature or report a bug?
A conflict, so more of a bug
What is the current behavior?
When using a browser extension that alters the DOM, like Emoji One, the Preact app might not be rendered to the correct spot, or even twice. For example, Emoji One injects an invisible element as the first child of body after some time. Since the app appears always to be rendered onto the first child, this can lead to problems.
If the current behavior is a bug, please provide the steps to reproduce.
serve
because I'm having problems with SimpleHTTPServer)What is the expected behavior?
The Preact app should explicitly be rendered to one specific element, e.g. determined by ID or reference.
(In case the selector isn't the cause of the problem, my ideas wouldn't help)
Please mention other relevant information.
The text was updated successfully, but these errors were encountered: