Skip to content

fix(core): run data stages tapped after the pipeline is built - #963

Closed
shahabdsh wants to merge 2 commits into
player-ui:mainfrom
shahabdsh:fix/late-resolve-data-stages
Closed

shahabdsh wants to merge 2 commits into
player-ui:mainfrom
shahabdsh:fix/late-resolve-data-stages

Conversation

@shahabdsh

@shahabdsh shahabdsh commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

DataController builds its data pipeline lazily, the first time anything reads or writes data, and calls resolveDataStages only at that moment. A stage tapped after that never runs, and nothing reports it.

Ordinary plugins hit this. Plugins tap player.hooks.dataController in registration order, and if a plugin registered earlier reads data in its tap (to seed or check a value, say), the pipeline is built right then. A plugin registered later that taps resolveDataStages from its own dataController tap is silently left out. Whether a data middleware runs then depends on plugin order, which the plugin adding it doesn't control.

Why it's needed now

#964 adds a streaming data plugin whose middleware serves large collections from outside the data model. Without this fix, that plugin has to detect being left out and add itself another way:

let inPipeline = false;
dataController.hooks.resolveDataStages.tap(this.name, (pipeline) => {
  inPipeline = true;
  return [...pipeline, this.middleware];
});

// Deferred so every plugin can tap resolveDataStages before the pipeline is built.
queueMicrotask(() => {
  // A plugin registered earlier may have built the pipeline from its own dataController tap.
  if (!inPipeline) dataController.getModel().addMiddleware(this.middleware);
});

Every plugin that adds a data stage would need the same workaround. With this fix, tapping resolveDataStages is enough, and #964 does only that. Its test "serves the collection when a plugin registered before it already read data" fails without this change.

Change

When a stage is tapped after the pipeline is built, DataController calls resolveDataStages again and passes the result to PipelinedDataModel.setMiddleware. The data lives in the base LocalModel, and the PipelinedDataModel instance and its hooks are kept, so nothing written earlier is lost and listeners on the model stay attached. Tapping before the pipeline is built works as before.

Rebuilding calls every resolveDataStages tap again. A tap that creates a new middleware on each call gets a fresh instance at that point; the taps in computed-properties and stage-revert-data reuse theirs, so they're unaffected.

The data controller architecture page now says that a late tap rebuilds the pipeline, instead of describing the stages as frozen.

Tests

  • data.test.ts: a stage tapped after the first read runs, data written before the tap is kept, and an onSet listener on the model still fires after the rebuild.
  • player.test.ts: when one plugin reads data in its dataController tap and a later plugin taps resolveDataStages, the later stage runs.

Two of these fail on main. The core/player vitest and eslint targets pass, as do the computed-properties and stage-revert-data suites.

Change Type (required)

Indicate the type of change your pull request is:

  • patch
  • minor
  • major
  • N/A

Does your PR have any documentation updates?

  • Updated docs
  • No Update needed
  • Unable to update docs

DataController builds its data pipeline the first time anything reads or
writes data, and resolveDataStages was only called at that moment. A
plugin that tapped resolveDataStages after another plugin had already
read data from its own dataController tap was silently left out of the
pipeline.

Rebuild the pipeline whenever a stage is tapped after it was built. The
data itself lives in the base LocalModel, and the PipelinedDataModel
instance and its hooks are kept, so nothing written earlier is lost.
@shahabdsh

Copy link
Copy Markdown
Contributor Author

Replaced by #967, which is stacked on #966.

@shahabdsh shahabdsh closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant