Skip to content

New setting .once.js e.g. +data.once.js #2566

@brillout

Description

@brillout

Description

pages/admin-panel/+Layout.js
# Data used by +Layout.js
pages/admin-panel/+data.once.js
# Setting pageContext.user
pages/+onCreatePageContext.once.js

If a hook uses the .once.js suffix then:

  • Upon client-side navigation, the hook isn't called again if it's shared (between the previous and next page)
    • Only make a pageContext.json request if a server-side hook should be called
  • All pageContext values set a .once.js hook are cached on the client-side
    • Thus, for server-side hooks, only passToClient properties are cached (on the client-side)
    • Deprecate the passToClient setting once: true in favor of .once.js
    • Requires: Flat pageContext #1268
    • Clear the entire cache upon page reload (i.e. the next URL equals the previous URL)? So that user can click on the active link to reload the page (or when the app calls reload()).

Optionally: #2565

  • I think we can release it as a MINOR BREAKING CHANGE?
    • It can break apps, but only unlikely so
    • It may make superfluous pageContext.json requests (the user will have to use .once.js to avoid these)
  • Migration guide for renderPage() with passToClient: [{ prop: 'user', once: true }]:
    - renderPage({ user })
    + renderPage({ req })
    +
    + // pages/+onCreatePageContext.once.js
    + export default (pageContext) => {
    +   pageContext.user = getUser(pageContext.req)
    + }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions