Bug: Server-Side-Render bug
See original GitHub issueCode:
function App() {
if (typeof window === 'undefined') {
return (
<div id="your-comp-id-server">
<div id="child-id-server">server</div>
</div>
)
}
return (
<div id="your-comp-id-client">
<div id="child-id-client">client</div>
</div>
)
}
// hydrate
ReactDOM.hydrate(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
React version: 17.0.1
Steps To Reproduce
- clone example
- run example
Link to code example:
https://github.com/fall-wind/may-react-ssr-bug
The current behavior
The expected behavior
<div id="your-comp-id-client">
<div id="child-id-client">client</div>
</div>
other information
source code:
function simpleCheckNodeType1SomeValueIsEqual(nodeType, instance, props) {
if (nodeType !== 1) {
return true
}
// just test
var checkList = ['id']
for (var i = 0; i < checkList.length; i++) {
var key = checkList[i]
// just test id different
var domVal = instance[key] || ''
var propsVal = (props && props[key]) || ''
if (domVal !== propsVal) {
return false
}
}
return true
}
function canHydrateInstance(instance, type, props) {
if (
instance.nodeType !== ELEMENT_NODE ||
type.toLowerCase() !== instance.nodeName.toLowerCase() ||
!simpleCheckNodeType1SomeValueIsEqual(instance.nodeType, instance, props)
) {
return null;
} // This has now been refined to an element node.
return instance;
}
l think just check nodeType and type is not enough. May need to check some properties.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Fix ServerSideRender component bug with Columns block ...
Description Fixes bug with component not working with Columns block. Addresses post-merge feedback from original PR. How has this been tested?
Read more >block editor - how to get a more significant error response from ...
I'm having a heck of a time with the ServerSideRender component for a Gutenberg block I'm developing. I'm seeing this error in the ......
Read more >Next.js 13 all pages are server-side render bug - Stack Overflow
All pages in next 13 (experimental app.dir) are server side rendered λ. Doesn't matter if there is any fetching inside them. Only slug...
Read more >wordpress/server-side-render | Block Editor Handbook
ServerSideRender is a component used for server-side rendering a preview of dynamic blocks ... The 'POST' value will cause an error on WP...
Read more >Gutenberg Components: ServerSideRender - Igor Benić
... ErrorResponsePlaceholder – by default, it will use the Placeholder component to say that there was an error with the provided block ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Using
yarn dev
I can see a warning though it’s slightly different because you hydrated an empty container. Right now you should seeBut this is because you’re not actually sending the server-rendered markup (see “view page source”).
From what I can tell
yarn dev
is not actually using the server. To use the server I have to runyarn build; dev:build-server; yarn dev:start;
first and visitlocalhost:3006
. There you don’t see a warning because that page uses the production build of React which strips a lot of warnings to save bundle size.If I copy & paste the server rendered output into
public/index.html
I get the warning described in https://github.com/facebook/react/issues/20414#issuecomment-741849996.You probably want to fix your dev setup so that it uses the server-rendered output. However, this is out of scope for this issue tracker so please check out https://reactjs.org/community/support.html or your favorite support channel.
Sorry, “The expected behavior” The information I provided is not very sufficient.
The expected behavior: div id “your-comp-id-server” should be “your-comp-id-client”; div id “child-id-server” should be “child-id-client”; text “client” is my expected behavior.