<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ryosuke Iwanaga</title>
    <description>The latest articles on Forem by Ryosuke Iwanaga (@riywo).</description>
    <link>https://forem.com/riywo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F539108%2F12f734a5-5cf5-49f4-b130-7d2c93d19314.png</url>
      <title>Forem: Ryosuke Iwanaga</title>
      <link>https://forem.com/riywo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/riywo"/>
    <language>en</language>
    <item>
      <title>Using GitHub Releases for patching Monorepo npm package</title>
      <dc:creator>Ryosuke Iwanaga</dc:creator>
      <pubDate>Thu, 29 Jul 2021 12:40:12 +0000</pubDate>
      <link>https://forem.com/riywo/using-github-release-for-patching-monorepo-npm-package-4k7a</link>
      <guid>https://forem.com/riywo/using-github-release-for-patching-monorepo-npm-package-4k7a</guid>
      <description>&lt;p&gt;When you find a bug in a npm package, you'll send a Pull Request (PR) to the original package. It would be great if your PR are merged quickly and released in the new version in npm registry. However, sometime it takes time but you want to use your bug fix right away. How can we do that?&lt;/p&gt;

&lt;p&gt;It is simple if the package is the root of GitHub repository i.e. not Monorepo because &lt;code&gt;package.json&lt;/code&gt; supports &lt;a href="https://docs.npmjs.com/cli/v7/configuring-npm/package-json#github-urls" rel="noopener noreferrer"&gt;GitHub URL in the dependencies&lt;/a&gt;. Since you have already sumitted the PR, you should have your own fork with the bug fix. Therefore, you can simply specify your branch in your &lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;npm&lt;/code&gt; command handles the rest including running &lt;code&gt;prepare&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Things are not so easy if the package is managed by a repository having multiple packages in it a.k.a. Monorepo. Unfortunately, there is no universal support by &lt;code&gt;package.json&lt;/code&gt; because each monorepo is managed differently. Therefore, you need to build the package on your forked branch and use it from your application.&lt;/p&gt;

&lt;p&gt;There are a bunch of solutions here, but I'd like to introduce a simple solution using GitHub Releases. In this solution, you just need a few manual steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build the monorepo e.g. &lt;code&gt;lerna run build&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create &lt;code&gt;.tgz&lt;/code&gt; package for your patched version e.g. &lt;code&gt;cd packages/package/dis &amp;amp;&amp;amp; npm pack&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Publish GitHub Releases i.e. &lt;code&gt;gh release create ... package.tgz&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use the artifact URL in your application's dependencies&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You need to run 1-3 whenever you update the branch, and probably need to reinstall packages in your application. You can automate these steps by GitHub Actions but you need to add &lt;code&gt;action.yaml&lt;/code&gt; to your branch which is unrelated to your PR. Thus, I think this solution will work better with a repository getting less frequent update in upstream.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;p&gt;Let me give you a concrete example I did. I needed &lt;a href="https://github.com/tw-in-js/use-twind-with/pull/21" rel="noopener noreferrer"&gt;this fix&lt;/a&gt; in my application right away. &lt;a href="https://github.com/tw-in-js/use-twind-with" rel="noopener noreferrer"&gt;The repository&lt;/a&gt; is monorepo and managed by &lt;code&gt;lerna&lt;/code&gt;. I've already checked the forked repository out and had a branch named &lt;code&gt;fix-classname&lt;/code&gt; on my laptop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build the monorepo
&lt;/h3&gt;

&lt;p&gt;Simply built the monorepo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  use-twind-with git:&lt;span class="o"&gt;(&lt;/span&gt;fix-classname&lt;span class="o"&gt;)&lt;/span&gt; npx lerna run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This created &lt;code&gt;dist&lt;/code&gt; directory under the package and it contains JavaScript files transpiled from TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  use-twind-with git:&lt;span class="o"&gt;(&lt;/span&gt;fix-classname&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;packages/preact
➜  preact git:&lt;span class="o"&gt;(&lt;/span&gt;fix-classname&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;ls&lt;/span&gt; ./dist
CHANGELOG.md         package.json         preact.d.ts          preact.esnext.js.map preact.mjs
LICENSE              preact.cjs           preact.d.ts.map      preact.js            preact.umd.js
README.md            preact.cjs.map       preact.esnext.js     preact.js.map        preact.umd.js.map
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create &lt;code&gt;.tgz&lt;/code&gt; package
&lt;/h3&gt;

&lt;p&gt;I just needed &lt;code&gt;dist&lt;/code&gt; directory only, so I ran &lt;code&gt;npm pack&lt;/code&gt; there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  preact git:&lt;span class="o"&gt;(&lt;/span&gt;fix-classname&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;dist
➜  dist git:&lt;span class="o"&gt;(&lt;/span&gt;fix-classname&lt;span class="o"&gt;)&lt;/span&gt; npm pack
npm notice
npm notice 📦  @twind/preact@1.0.5
npm notice &lt;span class="o"&gt;===&lt;/span&gt; Tarball Contents &lt;span class="o"&gt;===&lt;/span&gt;
npm notice 1.4kB CHANGELOG.md
npm notice 1.1kB LICENSE
npm notice 2.5kB README.md
npm notice 1.3kB package.json
npm notice 3.9kB preact.cjs
npm notice 3.7kB preact.cjs.map
npm notice 751B  preact.d.ts
npm notice 92B   preact.d.ts.map
npm notice 1.6kB preact.esnext.js
npm notice 3.4kB preact.esnext.js.map
npm notice 1.7kB preact.js
npm notice 3.4kB preact.js.map
npm notice 108B  preact.mjs
npm notice 1.5kB preact.umd.js
npm notice 3.3kB preact.umd.js.map
npm notice &lt;span class="o"&gt;===&lt;/span&gt; Tarball Details &lt;span class="o"&gt;===&lt;/span&gt;
npm notice name:          @twind/preact
npm notice version:       1.0.5
npm notice filename:      @twind/preact-1.0.5.tgz
npm notice package size:  6.9 kB
npm notice unpacked size: 29.8 kB
npm notice shasum:        b258372501fb0c0f392274e237f230575c56342f
npm notice integrity:     sha512-y+zDKMLhQNSUu[...]UpgzvPXvPto7w&lt;span class="o"&gt;==&lt;/span&gt;
npm notice total files:   15
npm notice
twind-preact-1.0.5.tgz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, I got &lt;code&gt;twind-preaxt-1.0.5.tgz&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Note: If you run &lt;code&gt;npm pack&lt;/code&gt; in the package root, the &lt;code&gt;.tgz&lt;/code&gt; file points TypeScript file as &lt;code&gt;main&lt;/code&gt; and won't work with &lt;code&gt;npm install&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Publish GitHub Releases
&lt;/h3&gt;

&lt;p&gt;To release, I needed a Git tag. I used a convention like &lt;code&gt;&amp;lt;original-tag&amp;gt;-&amp;lt;branch-name&amp;gt;&lt;/code&gt;. In this case, original tag was &lt;code&gt;@twind/preact@1.0.5&lt;/code&gt; and the branch name was &lt;code&gt;fix-classname&lt;/code&gt;. I needed to create and push the tag first. Then, published the tag with the packed &lt;code&gt;.tgz&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  dist git:&lt;span class="o"&gt;(&lt;/span&gt;fix-classname&lt;span class="o"&gt;)&lt;/span&gt; git tag @twind/preact@1.0.5-fix-classname
➜  dist git:&lt;span class="o"&gt;(&lt;/span&gt;fix-classname&lt;span class="o"&gt;)&lt;/span&gt; git push &lt;span class="nt"&gt;--tags&lt;/span&gt;
➜  dist git:&lt;span class="o"&gt;(&lt;/span&gt;fix-classname&lt;span class="o"&gt;)&lt;/span&gt; gh release create &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--target&lt;/span&gt; fix-classname &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--title&lt;/span&gt; @twind/preact@1.0.5-fix-classname &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--notes&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    @twind/preact@1.0.5-fix-classname twind-preact-1.0.5.tgz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the actual release page: &lt;a href="https://github.com/riywo/use-twind-with/releases/tag/%40twind%2Fpreact%401.0.5-fix-classname" rel="noopener noreferrer"&gt;https://github.com/riywo/use-twind-with/releases/tag/%40twind%2Fpreact%401.0.5-fix-classname&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;code&gt;gh&lt;/code&gt; command can be installed by &lt;a href="https://github.com/cli/cli#installation" rel="noopener noreferrer"&gt;https://github.com/cli/cli#installation&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Use the artifact URL
&lt;/h3&gt;

&lt;p&gt;Now, I got the &lt;code&gt;.tgz&lt;/code&gt; public URL &lt;code&gt;https://github.com/riywo/use-twind-with/releases/download/%40twind%2Fpreact%401.0.5-fix-classname/twind-preact-1.0.5.tgz&lt;/code&gt;. The last step was simply adding this to my application's &lt;code&gt;package.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"@twind/preact"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://github.com/riywo/use-twind-with/releases/download/%40twind%2Fpreact%401.0.5-fix-classname/twind-preact-1.0.5.tgz"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, ran &lt;code&gt;npm install&lt;/code&gt;. That's it! I compared the files under &lt;code&gt;node_modules/@twind/preact&lt;/code&gt; and they were at the patched version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  app git:&lt;span class="o"&gt;(&lt;/span&gt;main&lt;span class="o"&gt;)&lt;/span&gt; ✗ &lt;span class="nb"&gt;ls &lt;/span&gt;node_modules/@twind/preact
CHANGELOG.md         package.json         preact.d.ts          preact.esnext.js.map preact.mjs
LICENSE              preact.cjs           preact.d.ts.map      preact.js            preact.umd.js
README.md            preact.cjs.map       preact.esnext.js     preact.js.map        preact.umd.js.map
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;p&gt;You can do the similar thing without the public artifact, for example with Git Submodule/Subtree + custom npm scripts. This would be great because you don't have to manage GitHub Releases artifacts. However, the build process of your application might become complicated and take more time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I explained my solution to use a forked branch of monorepo packages via GitHub Releases. It requires a few manual steps but is relatively simple and easy to maintain.&lt;/p&gt;

</description>
      <category>npm</category>
      <category>github</category>
    </item>
    <item>
      <title>How to refresh next-i18next content update automatically?</title>
      <dc:creator>Ryosuke Iwanaga</dc:creator>
      <pubDate>Sun, 13 Jun 2021 08:51:04 +0000</pubDate>
      <link>https://forem.com/riywo/how-to-refresh-next-i18next-content-update-automatically-1e83</link>
      <guid>https://forem.com/riywo/how-to-refresh-next-i18next-content-update-automatically-1e83</guid>
      <description>&lt;h2&gt;
  
  
  tl;dr
&lt;/h2&gt;

&lt;p&gt;If you want to refresh your Next.js app using &lt;a href="https://github.com/isaachinman/next-i18next" rel="noopener noreferrer"&gt;&lt;code&gt;next-i18next&lt;/code&gt;&lt;/a&gt; automatically, you can do it like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;GetStaticProps&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;i18n&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next-i18next&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;serverSideTranslations&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next-i18next/serverSideTranslations&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useRouter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next/router&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../components/home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getStaticProps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;GetStaticProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;locale&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;i18n&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;reloadResources&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="p"&gt;...(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;serverSideTranslations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;locale&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;common&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])),&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRouter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;asPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;scroll&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Index&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What was the issue?
&lt;/h2&gt;

&lt;p&gt;When I started using &lt;a href="https://github.com/isaachinman/next-i18next" rel="noopener noreferrer"&gt;&lt;code&gt;next-i18next&lt;/code&gt;&lt;/a&gt;, I realized &lt;code&gt;next dev&lt;/code&gt; server only loaded the translation files once when initialized and never updated even if I reloaded the page on my browser since server side doesn't change. Whenever I updated the translation, I needed to restart &lt;code&gt;next dev&lt;/code&gt; server, which was bad developer experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternative solutions
&lt;/h2&gt;

&lt;p&gt;That is a known limitation and there are multiple GitHub issues like &lt;a href="https://github.com/isaachinman/next-i18next/issues/881" rel="noopener noreferrer"&gt;this&lt;/a&gt;. I was able to find two approaches:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Restart &lt;code&gt;next dev&lt;/code&gt; automatically whenever the content is updated.&lt;/li&gt;
&lt;li&gt;Poll API endpoint to monitor the content update and refresh the content.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The option 1 is simple and &lt;a href="https://www.npmjs.com/package/nodemon" rel="noopener noreferrer"&gt;&lt;code&gt;nodemon&lt;/code&gt;&lt;/a&gt; can easily achieve the goal. However, this is not "Fast Refresh" and takes a while.&lt;/p&gt;

&lt;p&gt;The option 2 seems better because &lt;code&gt;next dev&lt;/code&gt; server keeps running, but too complicated to implement internal API. It can be done without API like &lt;a href="https://github.com/hashicorp/next-remote-watch" rel="noopener noreferrer"&gt;&lt;code&gt;next-remote-watch&lt;/code&gt;&lt;/a&gt; which monitors files and calls Next.js's internal method to reload the page. I tried it but it still requires implementation of content refresh by calling &lt;code&gt;i18n.reloadResources()&lt;/code&gt; anyway. Also, page refresh is not "Fast Refresh" neither.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Then, I realized this can be done much simpler. First of all, it anyway requires polling from client side because there is no public method to execute &lt;a href="https://nextjs.org/docs/basic-features/fast-refresh" rel="noopener noreferrer"&gt;"Fast Refresh"&lt;/a&gt; from Next.js server side. Using internal method like &lt;code&gt;next-remote-watch&lt;/code&gt; does is not sustainable. Therefore, client side polling is the best way.&lt;/p&gt;

&lt;p&gt;However, setting up an API (i.e. &lt;code&gt;/api/something&lt;/code&gt;) for such a simple polling seems overkill. I thought it's probably enough by just re-rendering the page. With this approach, unless the virtual DOM of React has been updated, nothing happens on client side (I think).&lt;/p&gt;

&lt;p&gt;Now, how I can tell the translation files' change to the client? Next.js has a good mechanism to provide props to page i.e. &lt;code&gt;GetStaticProps&lt;/code&gt; which is already used by &lt;code&gt;next-i18next&lt;/code&gt; installation. I found &lt;a href="https://www.joshwcomeau.com/nextjs/refreshing-server-side-props/" rel="noopener noreferrer"&gt;a great solution&lt;/a&gt; to trigger this from client side.&lt;/p&gt;

&lt;p&gt;In addition, I found that it can call &lt;code&gt;i18n.reloadResources()&lt;/code&gt; there because &lt;code&gt;i18n&lt;/code&gt; instance is stored in a global value. I lazily implemented it with reloading &lt;code&gt;i18n&lt;/code&gt; at every request because my project doesn't have large translation files. This can eliminate file watcher logic at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclustion
&lt;/h2&gt;

&lt;p&gt;Now, by adding a simple &lt;code&gt;SetInterval()&lt;/code&gt; to refresh the page every 5 seconds on client side and reloading &lt;code&gt;i18n&lt;/code&gt; on every &lt;code&gt;GetStaticProps&lt;/code&gt; call, my Next.js pages are always in sync within 5 seconds. This is Next.js/React refresh, not browser refresh nor server restart, thus it's fast enough.&lt;/p&gt;

&lt;p&gt;Let me know if you have a better solution or if you find a drawback of this solution :)&lt;/p&gt;

&lt;h2&gt;
  
  
  Notes
&lt;/h2&gt;

&lt;p&gt;When your URL has hash (#foo), &lt;code&gt;router.replace()&lt;/code&gt; always scrolls up to the anchor and doesn't reload preps from the server. This is a known issue and there is a discussion on GitHub repository: &lt;a href="https://github.com/vercel/next.js/discussions/13804" rel="noopener noreferrer"&gt;https://github.com/vercel/next.js/discussions/13804&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>i18next</category>
      <category>react</category>
    </item>
  </channel>
</rss>
