-
-
Notifications
You must be signed in to change notification settings - Fork 356
[StimulusBundle] Skip mapping .ts controller if .js version is available #2702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
phasdev
wants to merge
1
commit into
symfony:2.x
Choose a base branch
from
phasdev:fix_2701
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/StimulusBundle/tests/fixtures/assets/more-controllers/other-controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// other-controller.js | ||
// @ts-ignore | ||
import { Controller } from '@hotwired/stimulus'; | ||
|
||
/* stimulusFetch: 'lazy' */ | ||
export default class extends Controller { | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seen the code just belove, what about we sort files
by name
ascending (.js
would be before.ts
)That way:
would only register the first one in the controller map, sa they would all have "foo-bar" as name.
We could
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a similar idea but later found out that controllers should be overridable. There is a test which checks for this feature:
ux/src/StimulusBundle/tests/AssetMapper/ControllersMapGeneratorTest.php
Line 115 in 61819ae
So skipping previously mapped controllers with the same name (
if (isset($controllersMap[$name])) continue;
) breaks that test since it doesn't allow controllers to be overridden.And since controllers can be overridden, we probably don't want to
sortByName()
as that may break the override order given in the controller paths.For example, given the following
config/packages/stimulus.yaml
:Then
controllers_a/hello-controller.js
would overridecontrollers_z/hello-controller.js
. But if we callsortByName()
thencontrollers_z/hello-controller.js
would overridecontrollers_a/hello-controller.js
. So devs could no longer specify controller override order instimulus.yaml
.When you say:
Are you referring to the
file_exists
call? I haven't looked at the PHP source code but according to this page: The file_exists doesn’t actually open the file. It just checks the file system to see if the file or directory is there where you specified. I'm assumingfile_exists
queries the filesystem instead of trying to allocate a file descriptor/read the file, so it shouldn't lock the file or otherwise consume resources. Also theloadCustomControllers
function is called once, either when runningconsole asset-map:compile
or when building the dev/test cache, so any performance impact should be negligible.Another nice thing about
if ($file->getExtension() === 'ts' && file_exists())
solution is the behaviour is explicit and localized to those few lines, so theloadCustomControllers
function is easier to understand and refactor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the solution
if ($file->getExtension() === 'ts' && file_exists())
which is more explicit than asortByName()
that works "by miracle" (I mean, without showing the intention behind)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you say:
Ah, I think I know what you mean now, i.e. skipping previously mapped controllers would bypass
ux/src/StimulusBundle/src/AssetMapper/ControllersMapGenerator.php
Line 80 in 61819ae
The
file_exists()
solution will also avoid opening files unecessarily.