Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

feat(universal): Allow for configuring if preboot complete() is called automatically (immediatelly) or manually (asynchronously) #552

Merged
merged 2 commits into from
Sep 22, 2016

Conversation

steve8708
Copy link
Contributor

  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines: https://github.com/angular/universal/blob/master/CONTRIBUTING.md#commit-message-format
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • What modules are related to this pull-request
  • express-engine
  • grunt-prerender
  • gulp-prerender
  • hapi-engine
  • universal-next
  • universal
  • webpack-prerender
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Feature
  • What is the current behavior? (You can also link to an open issue here)
    preboot complete() is called immediately upon client bootstrap, wether you want it to be or not
  • What is the new behavior (if this is a feature change)?
    Allows a configuration to override the automatic prebooting. This is especially useful is you have to do anything asynchronous before preboot complete runs, such as fetching data.

Usage is

imports: [
  UniversalModule.withConfig({ autoPreboot: false }), // default behavior is still `true`
]
  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
    No
  • Other information:

Open to any feedback on other ways to implement this feature and if good where to add tests and docs. Thanks!

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

1 similar comment
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@steve8708
Copy link
Contributor Author

CLA signed 👍

@googlebot
Copy link

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

…d automatically (immediatelly) or manually (asynchronously)

This is useful if you need to do anything asynchronous (e.g. fetch data) before preboot complete() is called.
@jeffwhelpley
Copy link
Contributor

@steve8708 sorry, can you change this so that it auto completes by default? Right now if you don't set autoPreboot then it won't complete. This will break everyone.

@MarkPieszak
Copy link
Contributor

Also erroring here in Travis tsc:

export function createGlobalProxy() {
                    ~~~~~~~~~~~~~~~~~
modules/universal/src/node/proxy-document.ts(116,17): error TS7030: Not all code paths return a value.

@@ -77,15 +78,22 @@ export const UNIVERSAL_CACHE = new OpaqueToken('UNIVERSAL_CACHE');
deps: []
},
{
provide: AUTO_PREBOOT,
useValue: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffwhelpley shouldn't this default the autoPreboot to true below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, including the token in the default providers array here allows the default behavior to remain unchanged.

anyone who doesn't provide a value for this token will get the default value true which will keep the current behavior the same for current universal users

only if someone explicitly provides a value for this token or provides a value for autoPreboot in the config object of UniversalModule.withConfig does this get overridden

@jeffwhelpley
Copy link
Contributor

@ca136 not if you don't set the AUTO_PREBOOT token. You are introducing that with this change, so when someone else upgrades, they won't have that set and will thus not have autoPreboot set even though they technically did have it before. Typically we want to try and ensure that when changes are introduced someone can upgrade without adversely affecting behavior. If you upgraded to this but didn't change anything else, preboot would go from automatically completing to not automatically completing.

@PatrickJS
Copy link
Contributor

LGTM

@steve8708
Copy link
Contributor Author

thanks @gdi2290 👍

@MarkPieszak looks like that tsc error was already on development but added another commit to this PR that resolves the error 👌

@PatrickJS PatrickJS merged commit aa4fc42 into angular:master Sep 22, 2016
@andresantos123
Copy link

andresantos123 commented Oct 11, 2016

@steve8708 with this PR I disabled the preboot.complete, but how it can be called now manually? The import of prebootClient from the old versions dont work anymore.

@steve8708
Copy link
Contributor Author

@andresantos123 come to think of it it may be nice to optionally export prebootComplete again like we did before

In the meantime you can see how we get the preboot client in universal here (A little ugly unfortunately, I believe it is this way to support a breaking API change among different versions of the preboot library) and we call it here;

So you should be able to do similar

var prebootClient;
try {
  prebootClient = require('preboot/__build/src/browser/preboot_browser');
  prebootClient = (prebootClient && prebootClient.prebootClient) || prebootClient;
} catch (e) {}

// .. and when you are ready
prebootClient().complete()

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants