Skip to content

Check for TransferState.isEmpty prevents serialization #47172

Closed

Description

@vz-tl

Which @angular/* package(s) are the source of the bug?

platform-server

Is this a regression?

Yes

Description

Until v13.3.x there wasn't any check before serializing TransferState in order to be rendered as part of the document.

In v14.1.x a check has been introduced to verify if TransferState.store has any keys (https://github.com/angular/angular/blob/14.1.x/packages/platform-server/src/transfer_state.ts#L26), otherwise no serialization will happen at all.

This now leads to no TransferState data being added to server-side rendered document, if for adding data to the store TransferState.onSerialize() is being used instead of TransferState.set().

The advantage of using TransferState.onSerialize() I see is, that applied callback will be invoked short before SSR is finished instead of somewhere at the beginning or during the app lifecycle on server side. So if data to be transferred would change in this period, it'd be more safe doing a late serialization.

Am I missing something or didn't I understand correctly how to add data to TransferState by using onSerialize?

Anyway, as behavior now changed because of that "empty store" check I see this as a regession, which has to be fixed.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

no TransferState data being added to SSR document

Please provide the environment you discovered this bug in (run ng version)

Node : 16.14.2
OS   : linux x64
npm  : 8.5.0

nx : 14.5.4
@nrwl/angular : 14.5.4

    "@angular/animations": "14.1.1",
    "@angular/cdk": "14.1.1",
    "@angular/common": "14.1.1",
    "@angular/compiler": "14.1.1",
    "@angular/core": "14.1.1",
    "@angular/forms": "14.1.1",
    "@angular/google-maps": "14.1.1",
    "@angular/localize": "14.1.1",
    "@angular/platform-browser": "14.1.1",
    "@angular/platform-browser-dynamic": "14.1.1",
    "@angular/platform-server": "14.1.1",
    "@angular/router": "14.1.1",

Anything else?

No response

Activity

  1. added
    area: server
    on Aug 17, 2022
  2. added this to the Backlog milestone on Sep 13, 2022
  3. modified the milestones: Backlog, needsTriage on Sep 13, 2022
  4. added
    regression
    on Oct 27, 2022
  5. self-assigned this
    on Oct 27, 2022
  6. added a commit that references this issue on Oct 28, 2022
    d2d9bbf
  7. added a commit that references this issue on Oct 28, 2022
    31a7ce1
  8. angular-automatic-lock-bot commented on Nov 28, 2022

    @angular-automatic-lock-bot

    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.

  9. locked and limited conversation to collaborators on Nov 28, 2022
  10. added a commit that references this issue on Feb 1, 2023
    3869f56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: serverbugregression

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions