Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi again @mjackson!
This PR is in regards to the other suggestion in your reply remix-run/react-router#6608 (comment):
Using
Router
with a manually-createdhistory
object seems like a reasonable enough workaround to me, because it's non-intrusive and only needs to be done in one place. I see that you've tried this in theseparate-imports
branch, which this PR is against.Unfortunately, the reason why your snippet works is because
Router
(the only import fromreact-router-dom
) is actually a re-export fromreact-router
, so Webpack prunes the entire react-router-dom.js file, and therefore doesn't mark any of the history imports as used. But if you import anything that isn't just a re-export, the bundler can't do this, and you once again end up with the entire contents ofhistory
(even if the thing you imported doesn't usehistory
at all).For example, in this PR, I do
import {Link, Router} from 'react-router-dom'
, and we once again end up withcreateHashHistory
in the output. So the workaround you're proposing means that you can't use e.g.Link
orNavLink
anywhere, which is a pretty severe limitation since they're such core parts of React Router's functionality.