<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zubeyr Anwar on Medium]]></title>
        <description><![CDATA[Stories by Zubeyr Anwar on Medium]]></description>
        <link>https://medium.com/@zubeyranwar?source=rss-6197c10d37ad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*h3Izfc9eesuB1EtoUvVyww.jpeg</url>
            <title>Stories by Zubeyr Anwar on Medium</title>
            <link>https://medium.com/@zubeyranwar?source=rss-6197c10d37ad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 05:14:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zubeyranwar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Fixing a Stuck MUI Select Menu During React Router Navigation + Suspense]]></title>
            <link>https://medium.com/@zubeyranwar/fixing-a-stuck-mui-select-menu-during-react-router-navigation-suspense-a10d05536058?source=rss-6197c10d37ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/a10d05536058</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[material-ui]]></category>
            <dc:creator><![CDATA[Zubeyr Anwar]]></dc:creator>
            <pubDate>Tue, 19 May 2026 04:39:15 GMT</pubDate>
            <atom:updated>2026-05-19T04:39:15.526Z</atom:updated>
            <content:encoded><![CDATA[<p>I ran into a surprisingly annoying issue with Material UI’s Select component while navigating between routes in React.</p><p>The bug only happened on the <strong>first selection</strong>.</p><p>When selecting a menu item:</p><ul><li>the route changed</li><li>the page suspended</li><li>a Suspense fallback rendered</li><li>and the Select menu stayed visually stuck open</li></ul><p>It looked like MUI never finished closing the dropdown.</p><h3>The Setup</h3><p>I had something like this:</p><pre>&lt;Select value={workspace} onChange={handleWorkspaceChange}&gt;<br>  {workspaces.map((workspace) =&gt; (<br>    &lt;MenuItem key={workspace.url} value={workspace.url}&gt;<br>      {workspace.name}<br>    &lt;/MenuItem&gt;<br>  ))}<br>&lt;/Select&gt;</pre><p>And inside the change handler:</p><pre>const handleWorkspaceChange = (e: SelectChangeEvent) =&gt; {<br>  const value = e.target.value;</pre><pre>  setWorkspace(value);</pre><pre>  navigate(`/dashboard${value}`);<br>};</pre><p>Looks harmless.</p><p>But because navigation triggered a rerender + Suspense fallback immediately, the Select component unmounted before MUI completed its internal close cycle.</p><p>The result:</p><ul><li>backdrop remained</li><li>menu portal stayed mounted</li><li>dropdown appeared stuck open</li></ul><p>Only on the first interaction.</p><h3>Why This Happens</h3><p>MUI Select uses:</p><ul><li>a portal</li><li>internal open state</li><li>transition lifecycle events</li></ul><p>When React Router navigation immediately triggers:</p><ul><li>Suspense</li><li>rerender</li><li>unmount</li></ul><p>…the Select never gets to properly fire its close lifecycle.</p><p>So the menu portal survives briefly in an inconsistent state.</p><h3>The Wrong Fixes I Tried</h3><p>I tried:</p><ul><li>blur()</li><li>refs</li><li>setTimeout</li><li>requestAnimationFrame</li><li>checking previous values</li><li>memoization</li><li>useCallback</li></ul><p>Some reduced the issue but none fully solved it.</p><p>Because the real issue was timing.</p><h3>The Real Fix</h3><p>The solution was simple:</p><h3>Do NOT navigate inside onChange</h3><p>Instead:</p><ol><li>store the pending value</li><li>close the Select first</li><li>navigate only after onClose</li></ol><h3>Working Solution</h3><pre>const [open, setOpen] = useState(false);</pre><pre>const pendingWorkspaceRef = useRef&lt;string | null&gt;(null);</pre><pre>const handleWorkspaceChange = useCallback(<br>  (e: SelectChangeEvent) =&gt; {<br>    const value = e.target.value;</pre><pre>    if (value === workspace) return;</pre><pre>    // store pending navigation<br>    pendingWorkspaceRef.current = value;</pre><pre>    // update local state<br>    setWorkspace(value);</pre><pre>    // close menu first<br>    setOpen(false);<br>  },<br>  [workspace],<br>);</pre><pre>const handleClose = useCallback(() =&gt; {<br>  setOpen(false);</pre><pre>  const pending = pendingWorkspaceRef.current;</pre><pre>  if (!pending) return;</pre><pre>  pendingWorkspaceRef.current = null;</pre><pre>  // wait until menu fully closes<br>  requestAnimationFrame(() =&gt; {<br>    navigate(`/dashboard${pending}`);<br>  });<br>}, [navigate]);</pre><p>Then wire it up:</p><pre>&lt;Select<br>  open={open}<br>  onOpen={() =&gt; setOpen(true)}<br>  onClose={handleClose}<br>  value={workspace}<br>  onChange={handleWorkspaceChange}<br>&gt;<br>  {workspaces.map((workspace) =&gt; (<br>    &lt;MenuItem key={workspace.url} value={workspace.url}&gt;<br>      {workspace.name}<br>    &lt;/MenuItem&gt;<br>  ))}<br>&lt;/Select&gt;</pre><h3>Why This Works</h3><p>The flow becomes:</p><ol><li>User selects item</li><li>Selection state updates</li><li>Select closes normally</li><li>onClose fires</li><li>Navigation happens afterward</li></ol><p>This allows MUI to clean up:</p><ul><li>portal</li><li>backdrop</li><li>transitions</li><li>focus management</li></ul><p>before Suspense remounts the tree.</p><h3>Final Thoughts</h3><p>This was one of those bugs where:</p><ul><li>the UI looked broken</li><li>the logic looked correct</li><li>and the actual problem was component lifecycle timing</li></ul><p>If you’re using:</p><ul><li>MUI Select</li><li>React Router</li><li>Suspense/lazy routes</li></ul><p>…and your dropdown gets stuck during navigation, delaying route changes until onClose is a working workaround.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a10d05536058" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Navilo (file-based routing npm package) works]]></title>
            <link>https://medium.com/@zubeyranwar/how-navilo-file-based-routing-npm-package-works-a06269ff5218?source=rss-6197c10d37ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/a06269ff5218</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react-router]]></category>
            <dc:creator><![CDATA[Zubeyr Anwar]]></dc:creator>
            <pubDate>Mon, 16 Mar 2026 07:02:46 GMT</pubDate>
            <atom:updated>2026-03-16T07:23:27.469Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Test" src="https://cdn-images-1.medium.com/max/1024/1*3VjEo_xR3TiX2D5pBdFT_A.png" /></figure><p>Before diving into internals, here is the short reason I built Navilo.</p><p>I found myself using Next.js mainly for App Router style file-based routing, while I was not using the API layer in many of my projects. That made me think: why not keep React Router (already the standard in React apps) and build a parser/generator layer around it to get the same routing experience?</p><p>That idea became <strong>Navilo</strong>.</p><p>The mental model in one line</p><p>Navilo scans files inside <em>src/app</em>, builds a route tree, converts it into React Router route definitions, and exposes it through a virtual module:</p><pre>import { router } from &#39;virtual:navilo-routes&#39;;</pre><p>Typical app structure Navilo reads</p><pre>src/app/<br>├─ layout.tsx<br>├─ page.tsx<br>├─ not-found.tsx<br>├─ blog/<br>│ └─ […slug]/<br>│ └─ page.tsx<br>└─ dashboard/<br>├─ layout.tsx<br>├─ loading.tsx<br>├─ page.tsx<br>└─ users/<br>└─ [id]/<br>└─ page.tsx</pre><p>Let’s take a look the package</p><p><strong>src/constants.ts (core constants)</strong></p><p>Defines:</p><ul><li>default plugin options (pagesDir: ‘src/app’)</li><li>virtual module IDs (virtual:navilo-routes and resolved id)</li></ul><p>Small file, but important because the whole plugin flow depends on these IDs.</p><p>src/types.ts (shared contracts)</p><p>Contains core types like:</p><ul><li>RouteFile</li><li>RouteType</li><li>RouteNode</li><li>ParserOptions</li><li>naviloOptions</li></ul><p>Think of this file as the schema between scan phase, parse phase, and generation phase.</p><p><strong>src/generator/parser/segmentParser.ts (segment syntax parser)</strong></p><p>Converts folder/file segment syntax into route path tokens.</p><p>Examples:</p><ul><li>[id] -&gt; :id</li><li>[…slug] -&gt; :slug*</li><li>[[…slug]] -&gt; :slug*?</li><li>(group) -&gt; ignored from path</li></ul><p>This is the “Next.js like syntax interpreter” part of Navilo.</p><p><strong>src/generator/createRoutes.ts (file scanning + normalization)</strong></p><p>This is where raw files become structured route metadata.</p><p>Main responsibilities:</p><ul><li>discover route files with fast-glob</li><li>detect file type (layout, page, error, loading, not-found)</li><li>normalize paths for cross-platform compatibility</li><li>generate component names from file location</li><li>extract route segments from file paths</li></ul><p>Output: <em>RouteFile[]</em></p><pre>export interface RouteFile {<br>    type: RouteType;<br>    path?: string;<br>    filePath: string;<br>    componentName: string;<br>    segments: string[];<br>}</pre><pre>export type RouteType = &#39;layout&#39; | &#39;page&#39; | &#39;error&#39; | &#39;loading&#39; | &#39;not-found&#39;;</pre><p><strong>src/generator/parser/routeTreeBuilder.ts (builds hierarchical route tree)</strong></p><p>Takes <em>RouteFile[]</em> and builds a nested <em>RouteNode</em> tree.</p><pre>export interface RouteNode {<br>    segment: string;<br>    path: string;<br>    fullPath: string;<br>    component?: string;<br>    indexPage?: string;<br>    layout?: string;<br>    error?: string;<br>    loading?: string;<br>    notFound?: string;<br>    children: Map&lt;string, RouteNode&gt;;<br>    isIndex?: boolean;<br>    metadata?: Record&lt;string, unknown&gt;;<br>}</pre><p>Key work here:</p><ul><li>creates nodes per normalized segment</li><li>attaches layout, error, loading, and notFound handlers</li><li>puts index pages into <em>indexPage</em></li><li>handles dynamic leaf routes using component</li><li>This file is the main core of navilo.</li></ul><p><strong>src/generator/parser/routeDefinitionGenerator.ts (React Router code generation)</strong></p><p>Transforms <em>RouteNode</em> tree into React Router route objects (as code string).</p><p>It also:</p><ul><li>generates index routes</li><li>injects wildcard not-found routes</li><li>propagates inherited <em>notFound</em></li><li>attaches route-level errorElement</li></ul><p>So this is where parsed structure becomes executable router config.</p><p><strong>src/plugin.ts (Vite integration)</strong></p><p>This file wires everything into Vite.</p><p>What it does:</p><p>1. resolves plugin options (pagesDir)</p><p>2. watches app files during dev server</p><p>3. invalidates virtual module on file changes</p><p>4. scans files with findRouteFiles</p><p>5. builds tree + definitions</p><p>6. returns generated module code exporting router</p><p>This is the runtime bridge between your filesystem and React Router.</p><p><strong>src/utils/index.ts (path matcher utility)</strong></p><p>Contains <strong>matchPath()</strong> helper to match a URL pathname against the built tree and return:</p><ul><li>matched component</li><li>extracted params (including catch-all arrays)</li></ul><p>It is useful for parser behavior validation and utility scenarios.</p><p><strong>End-to-end example</strong></p><p>Let’s say your app contains:</p><pre>src/app/<br>├─ layout.tsx<br>├─ page.tsx<br>├─ not-found.tsx<br>└─ blog/<br>└─ [id]/<br>└─ page.tsx</pre><p><strong>Step A: file discovery</strong></p><p><strong>createRoutes.ts</strong> detects each valid route file and creates <em>RouteFile[]</em>.</p><p>Example route metadata (conceptually):</p><pre>[<br>{ type: &#39;layout&#39;, segments: [], componentName: &#39;RootLayout&#39; },<br>{ type: &#39;page&#39;, segments: [], componentName: &#39;RootPage&#39; },<br>{ type: &#39;not-found&#39;, segments: [], componentName: &#39;RootNotFound&#39; },<br>{ type: &#39;page&#39;, segments: [&#39;blog&#39;, &#39;[id]&#39;], componentName: &#39;BlogIdPage&#39; }<br>]</pre><p><strong>Step B: segment normalization</strong></p><p><em>segmentParser.ts</em> transforms:</p><ul><li>blog stays blog</li><li>[id] becomes :id</li></ul><p><strong>Step C: route tree build</strong></p><p><em>routeTreeBuilder.ts</em> builds a tree:</p><ul><li>root node has layout and indexPage</li><li>child “blog” -&gt; child “:id” with route component</li><li>root notFound is attached</li></ul><p><strong>Step D: route definition generation</strong></p><p><em>routeDefinitionGenerator.ts</em> emits React Router route definitions with:</p><ul><li>root route</li><li>index route</li><li>“/blog/:id” route</li><li>wildcard “*” fallback using RootNotFound</li></ul><p><strong>Step E: virtual module output</strong></p><p><em>plugin.ts</em> returns generated code for:</p><pre>export { router };</pre><p>Then in app code you just use:</p><pre>import { RouterProvider } from &#39;react-router-dom&#39;;<br>import { router } from &#39;virtual:navilo-routes&#39;;<br>export function App() {<br>  return &lt;RouterProvider router={router} /&gt;;<br>}</pre><p><strong>Why this architecture works well</strong></p><ul><li>clear separation between scan, parse, tree, and generation</li><li>parser logic is testable without Vite runtime</li><li>plugin remains thin and focused on integration</li><li>you can get Nextjs like file routing while staying in React Router ecosystem</li></ul><p><strong>Final takeaway</strong></p><blockquote><em>“Navilo </em><strong><em>isn’t nearly as capable as</em></strong><em> the Next.js App Router.”</em></blockquote><p>It is just a developer-experience layer on top of React Router that converts file conventions into route definitions automatically. The result is a familiar file-based workflow with the flexibility and ecosystem compatibility of React Router. I will add more cases like <em>Parallel Routes and Intercepting Routes soon</em>.</p><p>Star repo if you like it: <a href="https://github.com/zubeyranwar/navilo">https://github.com/zubeyranwar/navilo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a06269ff5218" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functions as dependency in useEffect]]></title>
            <link>https://medium.com/@zubeyranwar/functions-as-dependency-in-useeffect-ea5f730b97ac?source=rss-6197c10d37ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea5f730b97ac</guid>
            <category><![CDATA[react-tips]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Zubeyr Anwar]]></dc:creator>
            <pubDate>Fri, 21 Mar 2025 13:44:54 GMT</pubDate>
            <atom:updated>2025-03-21T13:44:54.044Z</atom:updated>
            <content:encoded><![CDATA[<p>When using useEffect, you should be cautious about including functions as dependencies because this can cause an infinite loop. In JavaScript, functions are reference types, and when defined inside a component, <em>they are recreated with a new reference on every render</em>. This means useEffect will detect a change in the function reference each time, triggering the effect continuously.</p><p>To avoid this issue, you have two main options:</p><ol><li>Define the function inside useEffect if it’s only used there:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/0*dhAJA-bNztPnVkDW.png" /></figure><p>But sometimes there may case you need the functions to be outside useEffect block to access it.</p><p>2. Use useCallback when you need the function to be accessible outside useEffect:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/0*gIcXAR8x-VZ69gsd.png" /></figure><p><strong>useCallback</strong> memoizes the function, maintaining the same reference across renders. The function reference will only change when one of the dependencies specified in useCallback’s dependency array changes. This prevents unnecessary effect triggers and helps optimize performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea5f730b97ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>