Skip to content

Commit

Permalink
Merge pull request #348 from ckeditor/t/337
Browse files Browse the repository at this point in the history
Fix for partial loading or not loading at all of the GitHub Writer
  • Loading branch information
mlewand authored Aug 12, 2022
2 parents a404c50 + df4fd89 commit ac2a63a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,20 @@ export default router;

// Handle editors inside pjax containers.
{
document.addEventListener( 'pjax:start', ( { target } ) => {
document.addEventListener( 'turbo:before-visit', ( { target } ) => {
/* istanbul ignore next */
if ( process.env.NODE_ENV !== 'production' ) {
console.log( 'navigation started -> destroying editors', target );
}

Editor.destroyEditors( target );
}, { passive: true } );

document.addEventListener( 'pjax:end', () => {
document.addEventListener( 'turbo:render', () => {
setTimeout( () => {
/* istanbul ignore next */
if ( process.env.NODE_ENV !== 'production' ) {
console.log( `pjax ended -> running the router on "${ window.location.pathname }"` );
console.log( `navigation ended -> running the router on "${ window.location.pathname }"` );
}

router.run();
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ describe( 'Router', () => {
} );
} );

describe( 'pjax', () => {
it( 'should destroy editors before pjax', () => {
describe( 'turbo', () => {
it( 'should destroy editors before turbo navigation', () => {
const stub = sinon.stub( Editor, 'destroyEditors' );
expect( stub.called, 'no call before' ).to.be.false;

document.body.dispatchEvent( new CustomEvent( 'pjax:start', { bubbles: true } ) );
document.body.dispatchEvent( new CustomEvent( 'turbo:before-visit', { bubbles: true } ) );

expect( stub.calledOnce, 'one call after' ).to.be.true;
expect( stub.firstCall.calledWith( document.body ) ).to.be.true;
} );

it( 'should re-scan after pjax', done => {
it( 'should re-scan after turbo rendering', done => {
const stub = sinon.stub( router, 'run' );
expect( stub.called, 'no call before' ).to.be.false;

document.body.dispatchEvent( new CustomEvent( 'pjax:end', { bubbles: true } ) );
document.body.dispatchEvent( new CustomEvent( 'turbo:render', { bubbles: true } ) );

setTimeout( () => {
expect( stub.calledOnce, 'one call after' ).to.be.true;
Expand Down

0 comments on commit ac2a63a

Please sign in to comment.