Review main Merged

75164[BUGFIX] Fix page reloading on click on preview button

Tobias Jungmann CR +2 V +2 Normal +83 −10 updated 08/24/22, 11:15

Commit message

If a preview page is already open, clicking on the "view" button in the
content editor window would not reload the page. That means, that the
preview page would not show changes if the preview page url and the
target url are similar (e.g. only differentiate in hash/query or are
exactly the same).

This patch looks if a window with the given windowName is already open
(looking in `this.windows` did not work well because the existing
windows aren't saved in a global context, yet) and compares the URL of
an open window (if there's one) with the given URL. If the URLs are
similiar (i.e. the origin and the path name are the same) the page will
be reloaded.

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Benjamin Franzke +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Benjamin Franzke +1
    • core-ci +1 CI

Issues 1

Files 7

Review log 4356

Show 2331 earlier messages
  1. Tobias Jungmann uploaded patch set 1 07/13/22, 09:32

  2. Tobias Jungmann uploaded patch set 2 07/13/22, 09:46

  3. core-ci voted on patch set 1 V -1 07/13/22, 09:47 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29045

  4. core-ci voted on patch set 2 V -1 07/13/22, 09:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29047

  5. rgropp commented on patch set 2 V +1 07/15/22, 10:56

    Works as expected Page preview reloads correctly Tested following workflows: Page Module - CE editied -> save -> view - CE editied -> view -> save in dialog - CE editied -> save -> close -> view (page) - CE editied -> close -> save in dialog -> view (page) List Module - CE editied -> save -> view - CE editied -> view -> save in dialog - CE editied -> save -> close -> view (page) - CE editied -> close -> save in dialog -> view (page)
  6. Björn Jacob commented on patch set 2 CR -1 07/15/22, 14:18

    As discussed with Tobi, please extend the commit message. Let's have it for v11 as well. Please fix the tests.
  7. Tobias Jungmann uploaded patch set 3 07/15/22, 15:12

  8. core-ci voted on patch set 3 V +1 07/15/22, 15:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29227

  9. Tobias Jungmann updated the commit message in patch set 4 07/18/22, 06:36

  10. core-ci voted on patch set 4 V +1 07/18/22, 06:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29328

  11. rgropp commented on patch set 4 V +1 07/18/22, 08:11

    Works as expected Page preview reloads correctly Tested following workflows: Page Module * CE editied -> save -> view * CE editied -> view -> save in dialog * CE editied -> save -> close -> view (page) * CE editied -> close -> save in dialog -> view (page) List Module * CE editied -> save -> view * CE editied -> view -> save in dialog * CE editied -> save -> close -> view (page) * CE editied -> close -> save in dialog -> view (page)
  12. Andreas Kienast commented on patch set 4 CR -1 07/22/22, 07:12

    on it
  13. Andreas Kienast uploaded patch set 5 07/22/22, 07:23

  14. Andreas Kienast commented on patch set 5 V +1 CR +1 07/22/22, 07:24

    Thank you very much for your work!
  15. core-ci voted on patch set 5 V +1 07/22/22, 07:31 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29416

  16. Stefan Bürk commented on patch set 5 07/22/22, 20:10

    Thanks for your work on this patch. So, we open for different pages independent preview tabs ? Should we not simply open preview things in one preview tab and alwas reload it if a named window exists ? only for the "same page" which is "similar" it keeps it ? Once it opens a "second" tab and you switch back to previous page, you get a third preview tab. I'm not much an editor, but I think in older versions this was the case (not re-tested). Is this really the behaviour we want ?
  17. Tobias Jungmann commented on patch set 5 07/25/22, 06:40

    Reply

    No, we don't open multiple tabs. It's only one tab with a specific name ("newTYPO3frontendWindow"). Previews are always opened in this specific tab. But you don't need to reload the tab if you switch to another page (other URL, not similar). That's the behaviour it should have. Did your tests showed your described behaviour?

    Reply

    Thanks a lot for your fixes!
  18. Stefan Bürk commented on patch set 5 07/25/22, 07:51

    Reply

    Correct, my test showed different behaviour
  19. Tobias Jungmann commented on patch set 5 07/25/22, 10:22

    Reply

    Hmm, I cannot reproduce this behaviour. I only get one tab for previews Can you please describe your approach step by step? Which browser do you use?
  20. Stefan Bürk commented on patch set 5 07/25/22, 20:19

    Reply

    Ok, to be precise. Normal page layout is working as intended. But not if you are in a workspace and try to open it for different languages and switch in workspace between pages .. sometimes it reuses the tab, sometimes it opens a new one. So you are starting to collect tabs (in workspaces / multi language preview openenings). But I would guess, that's another part of the system. Do you want to investigate this and add it here too ? Or leave that for a dedicated patch ?
  21. Tobias Jungmann commented on patch set 5 07/29/22, 18:49

    Reply

    Oh, okay, I see. Thanks a lot for your precise description. I think I will leave it for another patch.
  22. Stefan Bürk commented on patch set 5 V +1 CR +1 07/30/22, 17:57

    Reply

    Okay with that.
  23. Simon Schaufelberger uploaded patch set 6 08/03/22, 20:51

  24. core-ci voted on patch set 6 V -1 08/03/22, 21:04 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29802

  25. core-ci commented on patch set 6 08/03/22, 21:13 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29802

  26. core-ci voted on patch set 6 V +1 08/03/22, 21:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/29802

  27. Björn Jacob voted on patch set 6 V +1 CR +1 08/08/22, 13:41

  28. rgropp voted on patch set 6 V +1 CR +1 08/09/22, 06:12

  29. Stefan Bürk commented on patch set 6 08/15/22, 07:29

    Mhh - can someone provide the 11.5 backport beforehand ?
  30. Tobias Jungmann commented on patch set 6 08/16/22, 11:20

    Reply

    I cherry-picked this patch: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75492 Had to adjust it to v11.5 typoscript/javascript logic. Please review and verify that patch, too.
  31. Stefan Bürk commented on patch set 6 CR -1 08/17/22, 06:53

    backport still have issues - thus putting temp -1 on the main patch to raise awareness for it
  1. Tobias Jungmann uploaded patch set 7 08/22/22, 09:48

  2. core-ci voted on patch set 7 V +1 08/22/22, 09:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/30345

  3. Björn Jacob voted on patch set 7 V +1 CR +1 08/22/22, 10:14

  4. Andreas Häfner voted on patch set 7 V +1 CR +1 08/22/22, 11:22

  5. Oliver Hader commented on patch set 7 CR -1 08/22/22, 13:38

    utility.ts:184

    "similar" might be misleading here... what about a different name like `sameOriginAndPath(a,b)`?

    utility.ts:194

    `const` for both uriObjects (skipping the `let` above)?

    utility.ts:200

    This `replace` call takes any first slash. I guess this should be more explicit like `replace(/^\//`)`... Besides that, `pathname` always has a trailing slash - couldn't it just be `url.origin + url.pathname` instead?

    utility.ts:215

    superfluous cast... what about two line? ``` try { new URL(url); return true; } ... ```

    window-manager.ts:39

    Why is the explicit type check for `Window` removed? What is `existingWindow === existingWindow.self` supposed to check?

    window-manager.ts:42

    There are scenarios where URL query-params shall not be ignored... ignoring query-params would be another/different option...
  6. Tobias Jungmann uploaded patch set 8 08/22/22, 17:06

  7. Tobias Jungmann commented on patch set 8 08/22/22, 17:06

    utility.ts:184 Reply

    Done

    utility.ts:194 Reply

    This won't work. Variables delcared in a try-catch-scope are not accesible outside of that scope.

    utility.ts:200 Reply

    You are right. But pathnames may have trailing slashes. You meant slashes at the beginning. I fixed it by adding the appropriate regex.

    utility.ts:215 Reply

    Done

    window-manager.ts:39 Reply

    Because `existingWindow instanceof Window` will always return false. Don't know exactly why, found this: https://github.com/jsdom/jsdom/issues/2740 The self-check is a weak method to check if the window is a window (and is opened). But I found a better solution (see change)

    window-manager.ts:42 Reply

    In my opinion it's a bit overdone to check for equality of the query params. I would reload the page even if the query parameters have changed. But if you insist, I will build in a query checker ;)
  8. core-ci voted on patch set 8 V +1 08/22/22, 17:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/30355

  9. Benjamin Franzke uploaded patch set 9 08/22/22, 18:40

  10. Benjamin Franzke commented on patch set 9 08/22/22, 18:40

    window-manager.ts:44

    This causes the URL hash not to be updated, if another content element on the same page was edited before. We should probably use existingWindow.location.replace(uri); before the call to reload(). Did so with latest patchset 9.
  11. core-ci voted on patch set 9 V +1 08/22/22, 18:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/30360

  12. Benjamin Franzke uploaded patch set 10 08/23/22, 20:34

  13. Benjamin Franzke commented on patch set 10 08/23/22, 20:34

    Reply

    Updated the cherry-pick. Therefore resolved.

    utility.ts:194 Reply

    Let's just move the concat into the try-block.

    utility.ts:200 Reply

    I do not understand why you've now added a regex that replaces trailing slashes, while the solution before removed leading slashes. Urls with different slashes are not similar, so we shouldn't unify here. I've dropped that part.

    window-manager.ts:39 Reply

    Note that it is not related to the jsdom issue that was linked (because jsdom is a DOM emulation for nodejs, e.g. unit testing, but isn't used in our case). Still you assertion/discovery is true, exstingWindow is not an instanceof Window, because the objects between multiple contexts are not shared. The behaviour is described in: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_contexts_e.g._frames_or_windows So this fix is fine, but deserves a comment IMO. Done.

    window-manager.ts:42 Reply

    I agree that we should check the query string. The user may have navigated the page and therefore the "view" action should assert that possible query strings are removed, otherwise it is not a real `view` of the canonical URL of the requested element/page. I've adapted the code to do so.
  14. core-ci voted on patch set 10 V +1 08/23/22, 20:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/30391

  15. Stefan Bürk commented on patch set 10 08/24/22, 04:26

    window-manager.ts:40

    This sentence is kind of broken. Or is a simple point missing ?
  16. Benjamin Franzke uploaded patch set 11 08/24/22, 06:09

  17. Benjamin Franzke commented on patch set 11 08/24/22, 06:09

    window-manager.ts:40 Reply

    Ack, the word "as" was missing after "here".
  18. core-ci voted on patch set 11 V +1 08/24/22, 06:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/30398

  19. Tobias Jungmann commented on patch set 11 08/24/22, 06:33

    utility.ts:200 Reply

    I missed the trailing slash before. We need this part because the page will not reload if you first open a new window without a trailing slash and then with a trailing slash. ``` const url = 'https://test.com/test';; window.open(url, 'test'); window.open(url + '/', 'test'); //does not reload the page ``` So imho we should keep that part.
  20. Tobias Jungmann commented on patch set 11 08/24/22, 06:42

    utility.ts:197

    This will return false if the query params are equal but have different order. `https://test.com?foo=1&bar=2` is the same like `https://test.com?bar=2&foo=1` but the strings are not equal. Shouldn't we check this before?
  21. Benjamin Franzke commented on patch set 11 08/24/22, 06:47

    utility.ts:197 Reply

    No, the browser will trigger a reload in that case. It is *another* resource from the view of the browser (doesn't matter that php treats it as the same), therefore an explicit reload() is not needed.

    utility.ts:200 Reply

    Your example uses a leading slash. https://test.com/test and https://test.com/test/ are different URLs and will browser to perform a new request. No reload is/should be needed.
  22. Tobias Jungmann commented on patch set 11 08/24/22, 07:01

    utility.ts:200 Reply

    Uh, you're right. Tried it on Chrome in an emtpy/new tab in the console and the browser wouldn't reload. But it reloads if you execute the code on a "normal" site. Interesting ...
  23. Stefan Bürk voted on patch set 11 V +1 CR +1 08/24/22, 11:13

  24. Stefan Bürk voted on patch set 11 V +2 CR +2 08/24/22, 11:15

  25. Stefan Bürk merged patch set 12 08/24/22, 11:15