Skip to content

Commit

Permalink
fix: add error for empty transition call
Browse files Browse the repository at this point in the history
  • Loading branch information
atellmer committed Dec 19, 2024
1 parent a291b8f commit 1c676fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/core/src/scheduler/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Scheduler {
[TaskPriority.LOW]: [],
};
private deadline = 0;
private lastId = 0;
private task: Task = null;
private scheduledCallback: WorkLoop = null;
private isMessageLoopRunning = false;
Expand All @@ -76,10 +77,15 @@ class Scheduler {
schedule(callback: TaskCallback, options: ScheduleCallbackOptions) {
const task = createTask(callback, options);

this.lastId = task.getId();
this.put(task);
this.execute();
}

getLastId() {
return this.lastId;
}

detectIsTransition() {
return this.task.getIsTransition();
}
Expand Down Expand Up @@ -242,6 +248,10 @@ class Task {
this.forceAsync = forceAsync;
}

getId() {
return this.__id;
}

getPriority() {
return this.priority;
}
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/start-transition/start-transition.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { detectIsFunction, illegal } from '../utils';
import { __useLoc as useLoc } from '../internal';
import { type Callback } from '../shared';
import { scheduler } from '../scheduler';
Expand All @@ -7,10 +8,17 @@ import { $$scope } from '../scope';

function startTransition(callback: Callback) {
const $scope = $$scope();
const id = scheduler.getLastId();

$scope.setIsTransitionZone(true);
try {
callback();
if (id === scheduler.getLastId()) {
const fn = $scope.getOnTransitionEnd();

detectIsFunction(fn) && fn(() => false);
illegal('startTransition must plan a new render!');
}
} finally {
$scope.setIsTransitionZone(false);
}
Expand Down

0 comments on commit 1c676fe

Please sign in to comment.