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

Fix hydration issue in the switchable runtime tests #35616

Merged
merged 3 commits into from Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,14 +1,14 @@
import getRuntime from '../utils/runtime'
import getTime from '../utils/time'
import Runtime from '../utils/runtime'
import Time from '../utils/time'

export default function Page() {
return (
<div>
This is a SSR RSC page.
<br />
{'Runtime: ' + getRuntime()}
<Runtime />
<br />
{'Time: ' + getTime()}
<Time />
</div>
)
}
Expand Down
@@ -1,14 +1,14 @@
import getRuntime from '../utils/runtime'
import getTime from '../utils/time'
import Runtime from '../utils/runtime'
import Time from '../utils/time'

export default function Page() {
return (
<div>
This is a SSR page.
<br />
{'Runtime: ' + getRuntime()}
<Runtime />
<br />
{'Time: ' + getTime()}
<Time />
</div>
)
}
Expand Down
@@ -1,14 +1,14 @@
import getRuntime from '../utils/runtime'
import getTime from '../utils/time'
import Runtime from '../utils/runtime'
import Time from '../utils/time'

export default function Page({ type }) {
return (
<div>
This is a {type} RSC page.
<br />
{'Runtime: ' + getRuntime()}
<Runtime />
<br />
{'Time: ' + getTime()}
<Time />
</div>
)
}
Expand Down
@@ -1,14 +1,14 @@
import getRuntime from '../utils/runtime'
import getTime from '../utils/time'
import Runtime from '../utils/runtime'
import Time from '../utils/time'

export default function Page({ type }) {
return (
<div>
This is a {type} RSC page.
<br />
{'Runtime: ' + getRuntime()}
<Runtime />
<br />
{'Time: ' + getTime()}
<Time />
</div>
)
}
Expand Down
@@ -1,14 +1,14 @@
import getRuntime from '../utils/runtime'
import getTime from '../utils/time'
import Runtime from '../utils/runtime'
import Time from '../utils/time'

export default function Page() {
return (
<div>
This is a static RSC page.
<br />
{'Runtime: ' + getRuntime()}
<Runtime />
<br />
{'Time: ' + getTime()}
<Time />
</div>
)
}
Expand Down
@@ -1,14 +1,14 @@
import getRuntime from '../utils/runtime'
import getTime from '../utils/time'
import Runtime from '../utils/runtime'
import Time from '../utils/time'

export default function Page({ type }) {
return (
<div>
This is a {type} page.
<br />
{'Runtime: ' + getRuntime()}
<Runtime />
<br />
{'Time: ' + getTime()}
<Time />
</div>
)
}
Expand Down
@@ -1,14 +1,14 @@
import getRuntime from '../utils/runtime'
import getTime from '../utils/time'
import Runtime from '../utils/runtime'
import Time from '../utils/time'

export default function Page({ type }) {
return (
<div>
This is a {type} page.
<br />
{'Runtime: ' + getRuntime()}
<Runtime />
<br />
{'Time: ' + getTime()}
<Time />
</div>
)
}
Expand Down
@@ -1,14 +1,14 @@
import getRuntime from '../utils/runtime'
import getTime from '../utils/time'
import Runtime from '../utils/runtime'
import Time from '../utils/time'

export default function Page() {
return (
<div>
This is a static page.
<br />
{'Runtime: ' + getRuntime()}
<Runtime />
<br />
{'Time: ' + getTime()}
<Time />
</div>
)
}
Expand Down
@@ -1,14 +1,14 @@
import getRuntime from '../utils/runtime'
import getTime from '../utils/time'
import Runtime from '../utils/runtime'
import Time from '../utils/time'

export default function Page() {
return (
<div>
This is a static page.
<br />
{'Runtime: ' + getRuntime()}
<Runtime />
<br />
{'Time: ' + getTime()}
<Time />
</div>
)
}
@@ -1,3 +1,14 @@
export default function getRuntime() {
return process.version ? `Node.js ${process.version}` : 'Edge/Browser'
export default function Runtime() {
let runtime

if (typeof window !== 'undefined') {
// We have to make sure it matches the existing markup when hydrating.
runtime = document.getElementById('__runtime').textContent
} else {
runtime =
'Runtime: ' +
(process.version ? `Node.js ${process.version}` : 'Edge/Browser')
}

return <span id="__runtime">{runtime}</span>
}
@@ -1,3 +1,12 @@
export default function getTime() {
return Date.now()
export default function Time() {
let time

if (typeof window !== 'undefined') {
// We have to make sure it matches the existing markup when hydrating.
time = document.getElementById('__time').textContent
} else {
time = 'Time: ' + Date.now()
}

return <span id="__time">{time}</span>
}