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

[v4] "Warning: useLayoutEffect does nothing on the server" when using SSR #152

Closed
finkrer opened this issue Oct 31, 2022 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@finkrer
Copy link

finkrer commented Oct 31, 2022

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.
    at Input (/node_modules/react-date-picker/dist/DateInput/Input.js:118:24)
    at YearInput (/node_modules/react-date-picker/dist/DateInput/YearInput.js:31:22)
    at div
    at DateInput (/node_modules/react-date-picker/dist/DateInput.js:232:5)
    at div
    at div
    at DateRangePicker (/node_modules/@wojtekmaj/react-daterange-picker/dist/DateRangePicker.js:93:5)
@wojtekmaj
Copy link
Owner

wojtekmaj commented Oct 31, 2022

That's new for me, but I'm not surprised too much. It was introduced in wojtekmaj/react-date-picker@4de8245 and the reason for this effect is to apply CSS width to an input based on its content width. If we use useEffect here, the UI jumps for a split second because the measurements are done too late.

@finkrer
Copy link
Author

finkrer commented Oct 31, 2022

Could you then make the component only render on the client, as the React devs recommend? Should make no difference in terms of behavior.

The warning spam kinda makes it impossible to work, I had to downgrade the package for now.

@wojtekmaj
Copy link
Owner

Sorry, which parts of the docs, or which post, are you referring to?

@wojtekmaj wojtekmaj added the bug Something isn't working label Nov 8, 2022
@finkrer
Copy link
Author

finkrer commented Nov 8, 2022

Sorry, I should've highlighted that. The error message links to this page: https://reactjs.org/link/uselayouteffect-ssr

@wojtekmaj
Copy link
Owner

Thanks!

Neither of these options are appealing to me.

  • Converting to useEffect is out of question for the reasons described above
  • "Lazy loading" component effectively breaks SSR rendering of the component which, aside from the measurements that must be done in the browser, is perfectly fine to render server side.

The only solution that makes any sense to me is this one - I'll go with this.

wojtekmaj added a commit to wojtekmaj/react-time-picker that referenced this issue Nov 8, 2022
wojtekmaj added a commit to wojtekmaj/react-date-picker that referenced this issue Nov 8, 2022
@wojtekmaj
Copy link
Owner

Fixed via wojtekmaj/react-date-picker@e95da80 - will be resolved with the next React-Date-Picker release. Note: React-DateRange-Picker will not update React-Date-Picker automatically - you'll have to update it yourself e.g. using yarn up react-date-picker -R, reinstall React-DateRange-Picker, or wait for the next React-DateRange-Picker update that bumps minimum React-Date-Picker version.

@wojtekmaj wojtekmaj changed the title Version 4.0.0 produces warnings with server side rendering [v4] "Warning: useLayoutEffect does nothing on the server" when using SSR Nov 11, 2022
@wojtekmaj
Copy link
Owner

you'll have to update it yourself e.g. using yarn up react-date-picker -R, reinstall React-DateRange-Picker

@wojtekmaj Perhaps you mean yarn upgrade react-date-picker -R ?

For legacy versions of Yarn, as far as I can remember, the command you proposed would be correct. :)

scudette pushed a commit to Velocidex/velociraptor that referenced this issue Apr 24, 2023
<h3>Snyk has created this PR to upgrade react-datetime-picker from 4.2.0
to 4.2.1.</h3>

:information_source: Keep your dependencies up-to-date. This makes it
easier to fix existing vulnerabilities and to more quickly identify and
fix newly disclosed vulnerabilities when they affect your project.
<hr/>

- The recommended version is **1 version** ahead of your current
version.
- The recommended version was released **22 days ago**, on 2023-04-01.


<details>
<summary><b>Release notes</b></summary>
<br/>
  <details>
    <summary>Package name: <b>react-datetime-picker</b></summary>
    <ul>
      <li>
<b>4.2.1</b> - <a
href="https://snyk.io/redirect/github/wojtekmaj/react-datetime-picker/releases/tag/v4.2.1">2023-04-01</a></br><h2>Bug
fixes</h2>
<ul>
<li>Pinned React-Calendar version to 4.0.0 to fix a bug with TypeScript
types.</li>
</ul>
      </li>
      <li>
<b>4.2.0</b> - <a
href="https://snyk.io/redirect/github/wojtekmaj/react-datetime-picker/releases/tag/v4.2.0">2023-01-18</a></br><h2>What's
new?</h2>
<ul>
<li>Added support for <code>data-testid</code> prop.</li>
<li>Increased compatibility with Deno (replaced <code>typeof window
…</code> checks with <code>typeof document …</code> checks).</li>
</ul>
<h2>What's changed?</h2>
<ul>
<li>Replaced Less with CSS. Don't worry - the CSS produced didn't
change, we just have one less tool in our stack.</li>
</ul>
<h2>Bug fixes</h2>
<ul>
<li>Fixed "Warning: useLayoutEffect does nothing on the server" warning
when using SSR (see: <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="1429902882"
data-permission-text="Title is private"
data-url="wojtekmaj/react-daterange-picker#152"
data-hovercard-type="issue"
data-hovercard-url="/wojtekmaj/react-daterange-picker/issues/152/hovercard"
href="https://snyk.io/redirect/github/wojtekmaj/react-daterange-picker/issues/152">wojtekmaj/react-daterange-picker#152</a>).</li>
<li>Fixed divider and leading zero positioning.</li>
<li>Fixed native calendar and time picker sometimes showing on
Safari.</li>
</ul>
      </li>
    </ul>
from <a
href="https://snyk.io/redirect/github/wojtekmaj/react-datetime-picker/releases">react-datetime-picker
GitHub release notes</a>
  </details>
</details>


<details>
  <summary><b>Commit messages</b></summary>
  </br>
  <details>
    <summary>Package name: <b>react-datetime-picker</b></summary>
    <ul>
<li><a
href="https://snyk.io/redirect/github/wojtekmaj/react-datetime-picker/commit/719e9d6ab0e131a891ed69da14664cb00f2d1f57">719e9d6</a>
v4.2.1</li>
    </ul>

<a
href="https://snyk.io/redirect/github/wojtekmaj/react-datetime-picker/compare/fca0ce422a7853ad78a38eb5a2d273fa2b9e547d...719e9d6ab0e131a891ed69da14664cb00f2d1f57">Compare</a>
  </details>
</details>
<hr/>

**Note:** *You are seeing this because you or someone else with access
to this repository has authorized Snyk to open upgrade PRs.*

For more information: <img
src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiIyYjYxMjJkYS02ZjBjLTQ0MjYtOTVhYy03MTk5ZmI4OWQ2MGYiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6IjJiNjEyMmRhLTZmMGMtNDQyNi05NWFjLTcxOTlmYjg5ZDYwZiJ9fQ=="
width="0" height="0"/>

🧐 [View latest project
report](https://app.snyk.io/org/scudette/project/76f4d127-566b-42ef-86f4-bdcbc92b90b4?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)

🛠 [Adjust upgrade PR
settings](https://app.snyk.io/org/scudette/project/76f4d127-566b-42ef-86f4-bdcbc92b90b4/settings/integration?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)

🔕 [Ignore this dependency or unsubscribe from future upgrade
PRs](https://app.snyk.io/org/scudette/project/76f4d127-566b-42ef-86f4-bdcbc92b90b4/settings/integration?pkg&#x3D;react-datetime-picker&amp;utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr#auto-dep-upgrades)

<!---
(snyk:metadata:{"prId":"2b6122da-6f0c-4426-95ac-7199fb89d60f","prPublicId":"2b6122da-6f0c-4426-95ac-7199fb89d60f","dependencies":[{"name":"react-datetime-picker","from":"4.2.0","to":"4.2.1"}],"packageManager":"npm","type":"auto","projectUrl":"https://app.snyk.io/org/scudette/project/76f4d127-566b-42ef-86f4-bdcbc92b90b4?utm_source=github&utm_medium=referral&page=upgrade-pr","projectPublicId":"76f4d127-566b-42ef-86f4-bdcbc92b90b4","env":"prod","prType":"upgrade","vulns":[],"issuesToFix":[],"upgrade":[],"upgradeInfo":{"versionsDiff":1,"publishedDate":"2023-04-01T14:18:27.372Z"},"templateVariants":[],"hasFixes":false,"isMajorUpgrade":false,"isBreakingChange":false,"priorityScoreList":[]})
--->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants