Strange re-render behavior when using <Switch> as a Route's root element #168
Unanswered
nathanbabcock
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Just noticed one more thing. It seems to also be affected by the shorthand way I defined the route. Changing from this: <Route path="/" element={Page} /> to this: <Route path="/" element={<Page />} /> Also seems to fix it. Is the first version (passing a |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Start with this:
The expected behavior is that you click the button to cycle between screens A, B, and C.
But that isn't what happens. Instead, every time you click the button, the entire
Page
component re-runs. You can see theconsole.log
appear multiple times in the console. In fact, you can never get to screens B or C since thecreateSignal
also reinitializes. My intuition would be that since theSwitch
is a child underneathPage
, thatPage
should render only once, regardless of how its children behave.Could someone explain the rendering logic that causes this? It seems to happen with the other conditional rendering components as well, such as
Show
. BTW, it can be fixed by wrapping theSwitch
in adiv
, or any other "real" JSX component.Or if it's a bug, I'll create an issue for it. But I am assuming that it's an implementation detail of Solid Router.
Beta Was this translation helpful? Give feedback.
All reactions