Skip to main content

Moving between pages

A member who taps a link in the community does not load a new page. The page they are on stays, and the part that changes is drawn in place, the way an app moves between its screens. This page says how that works and what a block, a widget or a kit has to do to keep it working. For the whole path of a new part, its rows, lists and events too, see Building for instant pages and live updates.

Three ways a page is shown​

  1. A whole load. The first page a browser opens, or one opened by its address, is drawn by the server as any WordPress page is.
  2. From its file. Every page of the menu has a file of its own, a static script in the uploads folder, and so do a member page and a post page (below). A tap on its link builds the page from that file, asks one request for what is in it now, and shows it. The document then has data-poly-move="file".
  3. From its HTML. Any other address (a post of a kit kind, a page with a query, a page that has no file yet) is fetched as HTML and drawn in place by the router of the WordPress Interactivity API.

Both moves are a client-side navigation of the Interactivity Router, in one router region, poly-community/app. A move from a file hands the router the page through the html parameter of navigate() instead of having it fetched, so the router diffs it, keeps elements by their data-wp-key and brings its styles and script modules as it does for any page. Every block of Poly Community declares that it works this way ("supports": { "interactivity": true }, Client-side navigation compatibility).

The second is the one to keep. After a page has loaded, the browser fetches only static files in the background (the page files, their templates), never a page, and a tap costs one request for data.

The page file​

Each page type has one file for every reader:

wp-content/uploads/poly-community/pages/members.07cd5154.js
wp-content/uploads/poly-community/pages/activity.e922f13f.js
wp-content/uploads/poly-community/pages/events.eab76af6.js

The name is the page and a hash of what the file holds, so a file never changes: a new one is written and the old one goes an hour later. It is served with a cache of a year. The file holds no key, so a page that draws as it did keeps its file and its name after a change, and browsers keep it too.

A page of many addresses has one file for all of them, its subject filled in by the browser from the row the page holds: a member page (each member, and each of their tabs), and a post page, one file for posts outside spaces and one for posts in a space. A post page file serves posts of the plain kind with no title of their own, by someone other than the reader. For a post in a space, the way back and the trail take the space name and address from the post row, and the reply box is in the file for every member, shown where the comments answer says the reader may reply, so a member of the space and a member outside it read the same file. The file in a space is drawn for two posts of two spaces of one type, with other names, that a visitor may open: whatever the page draws of one space differs between the two drawings, which refuses the file, so it never holds anything of one space. Each post file is drawn for posts with a title of their own or for posts without one, as most of the newest posts of the site are, and serves that kind alone. A post in a space of another type (a course space when the file is for groups), in a space inside another space, written as the space, or in a space whose replies take other tools moves by its HTML, as does any other post.

A space page has one file for every group of its shape, for a visitor so far (a member still moves by HTML, as where they stand in the space is drawn by the server). The browser finds the space from a card of it on the page or a post row that names it, and fills its name, address and the colour of its pictures. Its header data (spaceHead), its About data (spaceAbout) and its numbers come with the move, and so does what its widgets show (Who runs it, Rules, the faces of a few members in its header), as GET spaces/{id}/widgets answers it. A summary is drawn either way and shown by its data, so a space with none moves from the same file. A space of another type, with fields of its type filled in, inside another space, or with other tabs moves by its HTML.

What it holds:

  • The page as every reader sees it: one drawing for all, each part some readers alone see marked with whom it is for (below). Where a page still draws otherwise for a visitor, a member and an administrator, each kind: the first whole, the others written as they differ from it, and the browser builds the reader kind again from them.
  • The page drawn as a skeleton: every list named and none read, every part named and none read. Nothing in it is of the moment or of any reader.
  • What the head of the page needs: its scripts and styles, by reference.
  • The templates its lists draw from, once.

The file is made for a key. The key holds what the page is drawn from: the plugin version and its build, its scripts and styles, the saved templates and template parts, the settings, the locale, the theme and plugins, the page and its address. A change to any of them gives the page a new key, and a new file is made.

One drawing for every reader​

Where the kinds of a page come out the same, the file holds one drawing (all) and is named for every reader: a visitor, a member, a moderator and an administrator read the same bytes. The made record says one: '' for such a page, or why its kinds still differ. Most pages are one drawing: the feed, Members, member pages and their tabs, posts, a group page and its About tab, Spaces, Courses, Listings and the Events tabs.

A page is drawn as one when each block draws, in a file, what any reader may see, and marks each part only some readers see with the readers it is for. Poly_Community_Json_Moves::for_all() says the page drawn is a file. for_readers() marks a part:

function my_plugin_render_button( $attributes, $content, $block ) {
if ( Poly_Community_Json_Moves::for_all() ) {
// In a file: drawn for every reader, shown to members alone.
return Poly_Community_Json_Moves::for_readers( my_plugin_button_html(), 'loggedIn' );
}
// A page loaded whole: drawn for its reader alone, as ever.
return is_user_logged_in() ? my_plugin_button_html() : '';
}

The part is one element. Its first tag gets data-poly-for with the facts, and the browser hides it (.poly-not-for) for any reader the facts do not fit. The facts:

  • groups separated by spaces, any of which fits (can:{{s}}:invite can:{{s}}:inviteMenu),
  • facts in a group separated by commas, all of which must fit (loggedIn,!admin),
  • ! before a fact for readers who lack it,
  • a fact of state.reader by its name (loggedIn, admin, createSpace, startTopic, or one of your own),
  • a fact of the page subject: own:{id} (the member page is the reader own), joined:{id} and mod:{id} (the reader is in the space, runs it), can:{id}:{right} (a right of the reader in the space, from the move answer), with the subject id written as its mark (Poly_Community_Json_Moves()->subject_mark( 'space', $space_id )) in a file of many subjects.

Two parts for two kinds of reader are two marked parts side by side: Join and Manage on a space page are both drawn, each shown by where the reader stands.

A member own page​

A member page file serves the member it belongs to on the page itself and the tabs the core knows draw everything only that member sees with own:{id} (Posts, About, Followers, Following). On any other tab the member moves to their own page by its HTML. Once every part of your tab that only its member sees is drawn for them in the file, add its slug, and the member moves to it from the file too:

function my_plugin_own_tabs( $tabs ) {
$tabs[] = 'portfolio';
return $tabs;
}
add_filter( 'poly_community_json_move_own_tabs', 'my_plugin_own_tabs' );

A site administrator own page always moves by its HTML: their menu is drawn otherwise.

A right of your own in a space (may make an event there) is added to the reader rights the move answer brings, and a part marked with it:

function my_plugin_space_rights( $can, $space, $context ) {
if ( my_plugin_can_make_in( $space, $context ) ) {
$can[] = 'myThings';
}
return $can;
}
add_filter( 'poly_community_space_reader_rights', 'my_plugin_space_rights', 10, 3 );
$mark = Poly_Community_Json_Moves()->subject_mark( 'space', (int) $space->id );
echo Poly_Community_Json_Moves::for_readers( $new_thing_link, 'can:' . $mark . ':myThings' );

Where your block writes the subject id​

A file of many subjects (member pages, space pages, posts) has the subject id written as a mark the browser fills. The core marks where its own blocks write it. Where your block writes it elsewhere (a key of a list, an attribute of your own), say where, or the drawings for two subjects differ and the page has no file:

function my_plugin_subject_ids( $ids, $kind, $id ) {
if ( 'profile' === $kind ) {
$ids[ '~(data-my-plugin-member=")' . (int) $id . '(?=")~' ] = '${1}{{s}}';
}
return $ids;
}
add_filter( 'poly_community_json_move_subject_ids', 'my_plugin_subject_ids', 10, 3 );

$kind is profile, space or post. Mark only what is the subject id: a number marked that is not makes two drawings differ, which refuses the file. Photo albums marks its albums list of a member this way, Events its list and New event of a space, Live its Go live address and who is live in a space.

On a space page, the key of a part named unread is marked for you where the space id is one of its segments, between - or : (4-{id}, now:{id}:24). The REST path you named it with, and the key where your block writes it into the page, are yours to mark.

Facts a move brings​

Facts of every page come with each page (poly_community_viewer_facts, above). Facts only a page drawn from its file needs come with the move answer instead, worked out once a move, never in the page or the file: what the reader may post and with which tools, whether they may make a space or start a topic, what holds them back. Add your own:

function my_plugin_move_facts( $facts, $context ) {
$facts['myCanCreate'] = my_can_create( $context );
return $facts;
}
add_filter( 'poly_community_move_facts', 'my_plugin_move_facts', 10, 2 );

and mark the part with myCanCreate. A visitor gets none. A page loaded whole draws its reader own and asks no facts.

A part another plugin draws for members alone​

A part another plugin draws only when someone is logged in (a Message button) is drawn in a file as a stand-in member, then marked for the readers it is for:

$html = Poly_Community_Json_Moves::as_a_member( $profile_user_id, 'my_plugin_message_button_html' );
return Poly_Community_Json_Moves::for_readers( $html, 'loggedIn,!own:{{s}}' );

The first argument is a user the stand-in must not be (the member whose page it is). With true as the third argument the stand-in is an administrator, for a part drawn for the widest rights and shown by the reader own (the composer tools).

Who a file is for​

A page whose kinds still differ is served by kind. A file serves a reader whose fit it was drawn for. The fit is:

  • the reader shape (a visitor, a member, an administrator),
  • whether the reader is held back (a member whose posts wait for review),
  • for a page with a gated block of the core (the composer, the feed, pinned posts), what the reader chose there,
  • for a page with a fitted block, what that block says of the reader (below),
  • for the only administrator of a site, that administrator alone.

A moderator reads the member kind of a page where a drawing of that page as a moderator came out the same as the member kind. A moderator is one of the site team, or a member on the team of a space or a course. Each of the two kinds of moderator is checked on its own, the first time one of them reads the page (mods in the made record), so a page made for members waits for no moderator drawing. Where a page draws more for them, they move by HTML on that page alone. A moderator is never one of the readers a member kind is drawn as.

How a file is made​

After a page is shown, the server checks whether each page of the menu has a file for the reader fit. Where one is missing, it draws the page in the background, each kind as two readers of that fit who were active last, and keeps the file only where both drawings are the same and neither read anything of the moment. The tabs of a page are made with it.

All the pages wanted go to one background request, which draws them one after another, so the site draws one page at a time. After three minutes it hands the pages left to a request of its own. A drawing that finds the site busy (a time out, an error) stops it, and those pages are asked for again ten minutes later.

After a change that gives every page a new key (a deploy, a setting), each kind drawn and checked for the older key is drawn once for the new one. It is kept where it draws the same as before, apart from the versions of scripts, styles and icons. Only a kind that draws otherwise gets the whole check with two readers. So a deploy that changes nothing a page draws costs one drawing a kind.

A drawing is refused when:

  • a block of the page is not one a file may hold,
  • a block read something of the moment while drawing (a row of a member, a list, a part with data),
  • a block of another plugin draws with its own code,
  • no menu links to the page, or its address answers with something else (a login page).

An administrator reads why at /?poly_moves_made=1, or by GET poly-community/v1/moves/made. A refused kind is drawn again a day later, or as soon as its key changes.

The move​

  1. The browser loads the page files when it is idle.
  2. A tap on a link to a page with a file builds the reader kind of it, keeps the parts of the page that are the reader own (the menu, their spaces), and asks one request: the lists, parts and numbers the file names, with move={page}:{key}:{kind}:{fit} so the server checks that the file is for that reader.
  3. The router shows the page. Its lists, parts and numbers come in that one answer.

Styles and script modules the page needs and the page shown lacks are added as the file names them. A module comes as the WordPress router brings the modules of any page it shows, with the mark WordPress gives a module that loads on a move (data-wp-router-options, which Poly Community asks for every component script). Every community page names poly-community in its import map, so a module that imports the core gets the one copy already running, whatever page the move came from.

A page of the menu moves from its file at its plain address. Its tabs move from files of their own (below). A member page moves from the one file of every member, the member it is about filled in from the rows the page already holds, and so does each tab of a member page (About, Followers). Any other address with a query is fetched as HTML.

Tabs that draw the page again​

A tab that only narrows or sorts a list of the page asks that list again as JSON, in place. A tab that draws the page again (Events Past and Going, the Questions orders, the Forum tabs, the tabs of a member page) gets a page file of its own. Mark its link:

<a class="poly-tab" href="/community/events/?show=past" data-wp-on--click="actions.navigate" data-poly-file>Past</a>

As the page is drawn for its file, its links marked data-poly-file become pages of their own, up to eight a page, named after the page and what the address adds (events-past.3f9a2b1c.js, questions-active.…). Each is drawn and checked like any page. Its file is read when its page, or another of its tabs, is shown. The sort menu part does this for its orders with 'files' => true.

A link marked data-poly-file must be the same for every reader: its address is kept and named in the page state of every reader, a visitor included. Never mark a link whose address holds something of its reader (their handle, a key, an id only they have).

Building a block that works this way​

A block works in a page file when, drawn as a skeleton, it draws nothing of the moment and nothing of the reader beyond their shape. The check is Poly_Community_Address_Lists()->is_skeleton(): true while a file is drawn.

List the block​

The core lists its own blocks. A kit or another plugin lists its own with a filter:

function my_plugin_move_blocks( $blocks ) {
$blocks[] = 'my-block'; // a block of a component, poly-community/my-block, without poly-community/
$blocks[] = 'my-plugin/projects-button'; // a block of a plugin of its own, by its whole name
return $blocks;
}
add_filter( 'poly_community_json_move_blocks', 'my_plugin_move_blocks' );

A page whose template holds a block not listed has no file. Listing a block is a promise for every page that holds it, so a block that cannot keep it somewhere says so (below).

Rows and lists: name them, do not read them​

A list drawn from data (a list registered with Poly_Community()->live_data->register_list()) is named in a skeleton by its key in the slot it is drawn in, with no rows:

$lists = Poly_Community_Address_Lists();
$slot = $lists->new_slot();
if ( $lists->is_skeleton() ) {
$list = array( 'ids' => array(), 'type' => 'my_row', 'more' => false, 'page' => 1, 'args' => $args );
} else {
$list = $this->my_list( $args ); // its rows put for the reader
Poly_Community()->live_data->put_list( $key, $list );
}
wp_interactivity_state( 'poly-community', array( 'tileKeys' => array( $slot => $key ) ) );

The template draws the rows from the state (data-wp-each), so the same markup is drawn by the server on a whole load and by the browser after a move. The move asks the list by its key in its one request. The forum topics (inc/forum-lists.php) and the questions (inc/question-lists.php) are lists like that, each row a part of trusted HTML drawn for its reader. A kit list of posts through its own card goes through the core item list (poly_community_item_list), which names itself in a skeleton.

A list whose every row is one part of trusted HTML (its row holds the key of that part as html.row) is drawn by the getters of the core, so it draws before a kit script has loaded, as it has not after a move from a file:

<template data-wp-each--item="state.partRows" data-wp-each-key="context.item.id">
<div data-wp-bind--data-poly-tile="context.item.id">
<div class="poly-tile-part" data-wp-bind--data-poly-html="state.rowPartKey" data-wp-html="state.rowPart"></div>
</div>
</template>

Teaching is drawn this way (kits/courses/views/teaching-tiles.php). Give the list a rows callback beside its list, so a row is read again by its id (GET lists/{kind}?ids=) after a press or an event.

Parts: name them unread​

A part is data a template draws from by name and key (Poly_Community_Parts). In a skeleton, put() of a part refuses the drawing. Name it instead, with the REST path the browser asks it by:

$parts = Poly_Community_Parts::instance();
if ( $parts->unread( 'myWidget', $count, 'my-plugin/widget?count=' . $count ) ) {
return $this->view( 'widget', array( 'count' => $count ) ); // drawn empty, its data asked at the move
}
$parts->put( 'myWidget', $count, $this->widget_shown( $count ) );

The path answers the same data put() would hold. The template reads state.partHere. A widget that hides itself when empty says so in its data ('any' => (bool) $rows) and binds data-wp-bind--hidden="!state.partHere.any", so a file draws it hidden until its data comes. Waiting for an answer, Trending tags and the leaderboard work this way.

A part of the post a page shows​

A post page, and a component page of one item (an event, a course, a petition), is one file for every post of its kind. A block of yours on it that shows something of that post to some readers alone (its numbers to its author, a list to its team) puts it as a part keyed by the post id and names it unread with its route under the community REST namespace, {id} where the post id goes (items/{id}/my-notes, or petitions/{id}/signers?part=1 of Votes). Add the route to the post parts, and the move answer brings each reader their own:

function my_plugin_post_parts( $parts ) {
$parts['myPetitionNotes'] = 'items/{id}/my-notes';
return $parts;
}
add_filter( 'poly_community_json_move_post_parts', 'my_plugin_post_parts' );
if ( Poly_Community_Json_Moves::for_all() ) {
Poly_Community_Parts::instance()->unread( 'myPetitionNotes', (int) $item->id, 'items/' . (int) $item->id . '/my-notes' );
return $this->view( 'notes-part', array( 'id' => (int) $item->id ) ); // a holder bound to state.partHere
}

The route answers what the reader may see, nothing for another, and the holder hides itself on that. The post id in a route of the post parts is marked for you where {id} stands, an attribute of your own with it is yours to mark (poly_community_json_move_subject_ids, above). The core block Views and contacts works this way (itemStats, items/{id}/stats), and so do the blocks Ended (itemEnded, items/{id}/ended), Category path (termCrumbs, items/{id}/crumbs) and Contact the owner (contactOwner, items/{id}/contact), and the signers of a petition (petitionSigners). The Message button of Contact the owner is drawn as a member has it, the account of the writer of the post marked as {{s:user}}, and shown where the part says the reader gets it.

A kind with fields shows those for cards in a list and all of them on its own page: the row of a post holds both as two parts, as it holds the start and the whole of a long text, so a move to its page shows all of them.

What the reader may do: a fact, not a drawing​

What differs by reader but fits in the same markup is drawn for every member and shown by a fact of the reader:

function my_plugin_viewer_facts( $facts, $context ) {
if ( ! empty( $context['logged_in'] ) ) {
$facts['myCanCreate'] = my_can_create( $context );
}
return $facts;
}
add_filter( 'poly_community_viewer_facts', 'my_plugin_viewer_facts', 10, 2 );
<a class="poly-btn" href="..." data-wp-bind--hidden="!state.reader.myCanCreate">New thing</a>

The facts are the reader own and are never kept in a file. New event on the Events page is shown this way, as are Post in a space in the composer and Following in the feed bar.

Every kind of a file is public​

A page file is a static file: anyone can download it, a visitor included, and every kind in it, the administrator kind too. The fit only decides who is shown a kind, never who can read it. So no kind may hold anything a visitor must not read: no member name of a private space, no hidden topic, no address with a key. Such a block names it unread (a list, a part), asks it when it is used, or refuses the drawing (below). The filters of Questions refuse it when the reader sees other Q&A topics than a visitor does, so a members-only topic is never named in the file.

What a fact cannot say: a fitted block​

Some blocks draw something of their reader that changes the page around them, such as whether they may make a course, which puts New course in the head of Teaching. Such a block is fitted: a page that holds it is drawn for readers alike in that, and served only to them.

function my_plugin_fitted_blocks( $blocks ) {
$blocks[] = 'my-list';
return $blocks;
}
add_filter( 'poly_community_json_move_fitted_blocks', 'my_plugin_fitted_blocks' );

function my_plugin_move_fit( $fit, $blocks, $user_id ) {
if ( in_array( 'my-list', $blocks, true ) ) {
$fit['my-list'] = my_can_create( $user_id ); // for that member, never the current user
}
return $fit;
}
add_filter( 'poly_community_json_move_fit', 'my_plugin_move_fit', 10, 3 );

Keep the value the same for most members: each different value is a reader group of its own, and only the largest group gets a file. The value may differ by reader, but what it draws is still public, as every kind is.

A page only some members reach​

A page that only some members have in their navigation (Teaching, for those who build courses) is drawn as those who do. Say who reaches it:

function my_plugin_move_reaches( $reaches, $page, $user_id ) {
return 'kit-my-page' === $page ? $reaches && my_reaches( $user_id ) : $reaches;
}
add_filter( 'poly_community_json_move_reaches', 'my_plugin_move_reaches', 10, 3 );

Otherwise the page is drawn as members who have no link to it, and refused.

A block on the page of a space​

A space page file serves every space of its shape. A block a component puts on that page (above its posts, beside them) is drawn into the file once, so it must draw the same for every space of that shape, or say what it draws differently. Name the data of one space in a part keyed by the space, even as one segment of the key (4-{space id}): the file holds the key with a mark the browser fills. Where the block draws something of the space or of its reader by the server, put it in the shape of the space, and a space or reader of another shape moves to that page by its HTML:

function my_plugin_space_shape( $shape, $space, $context ) {
$level = my_plugin_space_level( $space );
if ( $level ) {
$shape['my-plugin'] = array( $level, my_plugin_reader_level( $context ) );
}
return $shape;
}
add_filter( 'poly_community_json_move_space_shape', 'my_plugin_space_shape', 10, 3 );

Leave the shape alone for the spaces where the block draws nothing, so those keep the file most spaces share. Ratings does this for its gate above the posts of a space rated for grown-ups.

What can never be in a file​

A block that sometimes draws what a file cannot hold (a space own rules, whether the reader watches something) says so as it draws it. The drawing is refused, and the page moves by HTML there:

Poly_Community_Json_Moves::not_in_file( 'my-block' );

Secrets are asked for when they are needed​

A page in a file is the same for every reader of its fit, so it holds no secret of a reader, and neither should a page drawn whole. Ask for it when it is used. Subscribe on the Events page asks its menu, with the member calendar address and its key, as it is pressed (GET poly-community/v1/events/subscribe).

Buttons inside rows drawn as parts​

A row drawn as a part of trusted HTML is not run by the Interactivity API. A button in a tile of a list (data-poly-tile, inside the list data-poly-tiles) names its action as usual (data-wp-on--click="actions.myAction"), and the action is registered for parts in the script module:

import { registerPress } from 'poly-community';

async function myAction( { button, context, id, post } ) {
const answer = await post( `my-plugin/things/${ id }/do`, {} );
return { done: true }; // the card new context, or nothing to read the card again
}
registerPress( 'myAction', myAction );

Links in parts move as any link does.

Classic themes​

Under a classic theme the community is on its pages, one for each section (the home, Members, Spaces), and the Community block of that page is its layout. A file is drawn from that block, with the Page type block of that page type in its main column. A move uses the file only inside the section it was drawn in: what the page has around the block (its title, the menu of the theme) belongs to that page, so a move to another section is fetched as HTML. A widget in the widget area of the Widgets screen keeps the page from a file unless it is a block widget whose blocks can be held in a file.

Times and places of the reader​

A page file is drawn in the site time zone. A block that writes times in the reader zone names no zone in a skeleton and lets the browser write its own, as the events list does, rather than asking the page again.

Checking a page​

  • /?poly_moves_made=1 as an administrator: each page, its file and why any kind of it was refused.
  • In the browser, the document has data-poly-move="file" after a move from a file.
  • In the tests, movesFromFile( page, cli, id ) of tests/fixtures/moves.ts waits for the page file, loads the page whole, moves to it from the feed and checks that it shows the same and that no page was fetched. The specs of Events (kits/events/tests/specs/moves.spec.ts), Questions (tests/specs/questions-moves.spec.ts) and Teaching (kits/courses/tests/specs/moves.spec.ts) use it.