-
-
Notifications
You must be signed in to change notification settings - Fork 16
"fetch: lazy": don't download until the controller is present #15
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
Conversation
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.
Amazing! I love that this feature will be available!
1fe23c4
to
2909057
Compare
Could you rebase? |
2909057
to
ca8d025
Compare
}); | ||
} | ||
} | ||
})) |
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.
Because this runs after babel, we need to rewrite this into "old" JavaScript to support all browsers. I have the code locally, just need to put it in here :)
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.
or maybe we can make this run before babel
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.
That would be nice... I just could not find a way to do that :/. We effectively would need to change the "filename" of the output source to something that ends in .js
and get Webpack to, sort of, "restart" the process so that the normal .js loader can match it. That may be possible, but I couldn't find away. And... really, we ship "dist" code normally that has been pre-compiled with Babel. This just a special case of doing the same (the strangeness being that I'll rewrite this to ES5 manually).
24634b3
to
2b9cd8f
Compare
* @param {Number} indentationSpaces Amount each line should be indented | ||
*/ | ||
|
||
module.exports = function generateLazyController(controllerPath, indentationSpaces) { |
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.
why do we have dist files committed in this repo ?
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.
We should clean this up. Some dist files are needed because they're read at runtime in the browser - specifically the src/index.js
file (which the user imports directly from their code and uses. But other things - like these loaders - are only executed at build time and do not need a dist.
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.
even for the necessary ones, I don't think they need to be committed, as the npm ecosystem relies on a separate publishing step and so the VCS content and the package content can be different.
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.
You're right about that too. None of them should be committed. However, we would need to make sure there was a more sophisticated build+publish functionality. The dist files are also committed in symfony/ux for the same reason: ease of distribution (because there is no automated build/release procedure).
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.
symfony/ux packages are not distributed through npm but through composer.
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.
npm already has a built-in automation: it will run the prepublishOnly
script before building the archive for publication.
you only need to update the package.json to make that prepublishOnly
script run npm run build
and that's automated.
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.
This repo could definitely not include the dist files at all indeed. I added them without too much thoughts after having added them in symfony/ux.
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.
let's fix that in another PR
d2bac9c
to
e3b9161
Compare
510db70
to
1007648
Compare
I've updated the PR to use a |
in `controllers.json` to `lazy`, your controller will not | ||
be downloaded until the controller element first appears on the page. | ||
|
||
* The `webpackMode` option in `controllers.json` was deprecated. Use |
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.
We should open a PR on UX and Flex to change this there. Do you have time to do it?
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 already did! :) symfony/ux#53
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.
But flex - I hadn’t thought about that piece - I’ll get that done
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.
Flex PR: symfony/flex#735
Keeping webpackMode for support of people using an old Flex version
1007648
to
a9028b2
Compare
Thanks Ryan. |
…ge#15 (weaverryan) This PR was merged into the main branch. Discussion ---------- Changing webpackMode to fetch - see symfony/stimulus-bridge#15 | Q | A | ------------- | --- | Bug fix? | yes(ish) | New feature? | no | Tickets | none | License | MIT Hi! If symfony/stimulus-bridge#15 is merged, this updates the keys for all the UX packages. The old `webpackMode` is kept for now. This will prevent errors if you're using an "old" Flex version (a version before this PR symfony/flex#735). We can remove that... eventually... Cheers! Commits ------- 27f7115 Adding fetch - see symfony/stimulus-bridge#15
Keeping webpackMode for support of people using an old Flex version
Keeping webpackMode for support of people using an old Flex version
Keeping webpackMode for support of people using an old Flex version
Keeping webpackMode for support of people using an old Flex version
Keeping webpackMode for support of people using an old Flex version
This PR was merged into the main branch. Discussion ---------- Lazy controllers for user-land controllers Hi! This allows users to make their own controllers "lazy" by adding a special comment above their controllers: ```js // assets/controllers/hello_controller.js import { Controller } from 'stimulus'; /* stimulusFetch: 'lazy' */ export default class extends Controller { // ... } ``` When you do this, your controller (and its dependencies) are *not* included in the main `app.js` built file. Instead, they are split into their own chunk/file. This file is loaded asynchronously the moment that the *first* element appears on the page for this controller (e.g. `<div data-controller="hello">`). This follows up on #15 (and only the last commit is new to this PR). The `/* stimulusFetch: 'lazy' */` is inspired by Webpack's `/* webpackMode: 'lazy' */` comments and uses the same mechanism to parse them. To activate this, you only need to process your controllers through a new loader: ```diff // assets/bootstrap.js export const app = startStimulusApp(require.context( - './controllers', + '@symfony/stimulus-bridge/lazy-controller-loader!./controllers', true, /\.(j|t)sx?$/ )); ``` That looks a bit ugly, but this is code that we'll give users via the recipe anyways. I've tested this in a real app and it works beautifully ❤️ . Cheers! Commits ------- bbf8ab0 Implementing a way to make user-land controllers lazy
… "fetch" mode (weaverryan) This PR was merged into the 1.9-dev branch. Discussion ---------- Changing to support next version of stimulus bridge with "fetch" mode Partner to symfony/stimulus-bridge#15 and symfony/ux#53 The tricky part about this is that, if the user has `stimulus-bridge` 1.x, then their `controllers.json` file needs `webpackMode`. If they have `stimulus-bridge` "next" (we're thinking it'll be 2.0), then their `controllers.json` file needs `fetch`. This means that Flex has a "hard break" and sorta just needs to assume that the user has the "new" version. We made the decision - to go from `webpackMode` to `fetch` because the setting no longer is truly the same as `webpackMode`. However, if we wanted to make the upgrade path easier, we could revert that and use `webpackMode` in 2.0 as well (instead of changing to `fetch`). Commits ------- 0c452b5 Changing to support next version of stimulus bridge with "fetch" mode
…(kl3sk) This PR was merged into the main branch. Discussion ---------- Update README deprecated "webpackMode" in favor of "fetch" After @weaverryan symfony/stimulus-bridge#15 PR Encore complains: `The "webpackMode" config key is deprecated in controllers.json. Use "fetch" instead, set to either "eager" or "lazy".` | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Features and deprecations must be submitted against branch main. --> Commits ------- 463f429 Update README.md
After @weaverryan symfony/stimulus-bridge#15 PR Encore complains: `The "webpackMode" config key is deprecated in controllers.json. Use "fetch" instead, set to either "eager" or "lazy".`
Keeping webpackMode for support of people using an old Flex version
…ge#15 (weaverryan) This PR was merged into the main branch. Discussion ---------- Changing webpackMode to fetch - see symfony/stimulus-bridge#15 | Q | A | ------------- | --- | Bug fix? | yes(ish) | New feature? | no | Tickets | none | License | MIT Hi! If symfony/stimulus-bridge#15 is merged, this updates the keys for all the UX packages. The old `webpackMode` is kept for now. This will prevent errors if you're using an "old" Flex version (a version before this PR symfony/flex#735). We can remove that... eventually... Cheers! Commits ------- 27f7115 Adding fetch - see symfony/stimulus-bridge#15
After @weaverryan symfony/stimulus-bridge#15 PR Encore complains: `The "webpackMode" config key is deprecated in controllers.json. Use "fetch" instead, set to either "eager" or "lazy".`
…(kl3sk) This PR was merged into the main branch. Discussion ---------- Update README deprecated "webpackMode" in favor of "fetch" After @weaverryan symfony/stimulus-bridge#15 PR Encore complains: `The "webpackMode" config key is deprecated in controllers.json. Use "fetch" instead, set to either "eager" or "lazy".` | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Features and deprecations must be submitted against branch main. --> Commits ------- 463f429 Update README.md
Hi!
This deprecates the
webpackMode
option incontrollers.json
and replaces it with a newlazy
option that can be set toeager
orlazy
.The
lazy
mode is quite a bit smarter than the oldwebpackMode: 'lazy'
. When you use this, the controller (and its dependencies) isn't downloaded until the correspondingdata-controller
appears on the page. This is great for things like chartjs, which is quite huge, but probably you don't have it on every page and a tiny delay is no problem.PR to update the UX packages: symfony/ux#53
Cheers!
Fixes #3