Remove prepended forward slash when mapping.path is empty #192
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.
While using ViewComponents I ran into an issue with sidecar loaded js files not being mapped correctly when using importmap-rails and propshaft. The issue has been raised in Propshaft Issue #87 and ViewComponents Issue #1064 neither of which provided solutions I wanted to use.
Digging into it I found that using the following config nearly produced the desired output:
I assume Propshaft interprets the path as absolute and fails to digest it.
This fix just adds
reject(&:empty?)
to remove empty strings allowingmapping.path
to essentially overwritemapping.under
allowing the path to be resolved by Propshaft.After fix:
The test covers the ViewComponent scenario of a directory located at
app/components
which is the reason for passingto: ""
in the first place.If there's a legitimate reason for requiring the forward slash then I assume
to: "/"
would still work.