Comments (6)
Are you able to trace the calls? This repo is the entire source for the string renderer and doesn't contain the text componentDidMount
- I can't imagine how it would be getting called. Perhaps you're seeing this issue? preactjs/preact#524
from preact-render-to-string.
This is the trace I'm getting:
ReferenceError: window is not defined
at Modal.componentDidMount (D:/Dev/_Projects/Vibescout/vibescout-web-v3/src/client/react/uiComponents/modal/Modal.js:26:5)
at Modal.target.(anonymous function) (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\mobx-react\\index.js:259:13)
at flushMounts (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\preact\\src\\vdom\\diff.js:22:23)
at renderComponent (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\preact\\src\\vdom\\component.js:186:4)
at Modal.forceUpdate (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\preact\\src\\component.js:80:7)
Reaction.onInvalidate (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\mobx-react\\index.js:352:81)
at Reaction.runReaction (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\mobx\\lib\\mobx.js:1281:22)
at runReactionsHelper (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\mobx\\lib\\mobx.js:1397:35)
at reactionScheduler (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\mobx\\lib\\mobx.js:1379:47)
at runReactions (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\mobx\\lib\\mobx.js:1383:5)
at endBatch (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\mobx\\lib\\mobx.js:1174:9)
at endAction (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\mobx\\lib\\mobx.js:689:5)
at executeAction (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\mobx\\lib\\mobx.js:656:9)
at UIStore.res (D:\\Dev\\_Projects\\Vibescout\\vibescout-web-v3\\node_modules\\mobx\\lib\\mobx.js:644:16)
at pageErrorCatchRoute (D:/Dev/_Projects/Vibescout/vibescout-web-v3/src/server/router/pageRouter/routes/errorCatchRoute.js:41:32)"}
I'm using MobX for my state before rendering and injecting all my React components with that state using the @inject
and @observer
decorators. I also seem to be getting another really strange issue where Preact seems to be attaching a new node onto my state object that looks like this (from console.dir
):
children:
[ VNode {
'0': [Circular],
nodeName: [Object],
attributes: [Object],
children: [Object],
key: undefined,
preactCompatUpgraded: true,
preactCompatNormalized: true,
length: 1 } ] }
And this is causing a TypeError: Converting circular structure to JSON
error when I'm trying to insert that state into my HTML with JSON.stringify
.
All quite strange. This is what my React looks like to be rendered to string:
<Provider {...stores}>
<MuiThemeProvider muiTheme={muiTheme}>
<RouterContext {...props} />
</MuiThemeProvider>
</Provider>
I'm using a Mobx Provider
there, MuiThemeProvider
from Material-UI and then the RouterContext
from React-Router.
The stores passed into Provider
seem to be getting mutated with that extra children
node.
from preact-render-to-string.
Ah - it seems like you're using a modal dialog, which is invoking renderSubTreeIntoContainer, which does DOM rendering. That children
node is odd, but it doesn't seem like it has anything to do with Preact - it's probably there in React too, but not a circular reference. Worth checking the stringified JSON.
Another thing that seems odd, maybe relates the two: perhaps the failure to serialize (due to the circular reference) is triggering error handling components you're not triggering in React? The stack starts at one (errorCatchRoute.js
)
from preact-render-to-string.
That pageErrorCatchRoute.js
is just a catch all for errors when I'm rendering React pages from the server. It them mutates the UIStore to show a modal straight away on page load depending on the error. I think I need to create another error catch just for the actual renderToString
function to get a better idea of what's going on.
I have a feeling this could be something to do with mobx-react
and preact-compat
, perhaps there is some incompatibility with the injecting of state into the components and such. Because it seems that this error originates from actions being called and reactions happening through that when I'm rendering the components (when they should only be rendering, not reacting at all).
from preact-render-to-string.
Yes - I think setState() is triggering a DOM render here, which is on Preact. Probably still want to skip the mobx error handling on the server though, at best it would result in a no-op.
from preact-render-to-string.
Closing since this should have been fixed ~2y ago in 0b853e9. Please re-open if its still an issue!
from preact-render-to-string.
Related Issues (20)
- With Nextjs Error: Objects are not valid as a child. Encountered an object with the keys {} HOT 5
- Shallow rendering and parameter object serialization HOT 1
- Rendering shallow makes a Fragment into a <p> HOT 4
- Async Render for Async Components in the tree?
- Behavior for falsy data attributes not same as preact.
- 5.2.5 breaks server side rendering of @preact/signals HOT 2
- renderToString with {pretty: true} causes undesirable newlines with text nodes HOT 1
- Rendering asynchronous component throws an error HOT 9
- Meta charset not rendered as expected HOT 1
- Void elements have whitespace at closing
- Using effects from @preact/signals causes memory leak HOT 2
- CommonJS bundle broken for v6 HOT 1
- unpkg package seems failed HOT 2
- Unable to import shallowRender from preact-render-to-string/jsx due to TypeScript type errors
- preact and htm function does not return html when ssr rendered from mjs file HOT 3
- xlink:href becomes xlink::href
- `options._diff` not called for implicit Fragments HOT 2
- `preact/debug` warnings not thrown because `vnode.__k` is not set
- Stream Rendering Roadmap HOT 1
- Invalid nesting detection with `preact/debug` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from preact-render-to-string.