Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove full reload of preview #12517

Closed
Tracked by #11492
mlqn opened this issue Mar 15, 2024 · 12 comments · Fixed by #12534
Closed
Tracked by #11492

Remove full reload of preview #12517

mlqn opened this issue Mar 15, 2024 · 12 comments · Fixed by #12534
Labels
area/app-preview Area: Related to test and preview of apps that are developed in Altinn Studio. kind/chore status/ready-for-dev Status: Used for issues that are ready for development. Has been through grooming.

Comments

@mlqn
Copy link
Contributor

mlqn commented Mar 15, 2024

Description

The current preview fully reloads when we update something in a layout.

An easy solution to fix it could be to invalidate React queries in the preview to force it to retrieve the new layout.

Before

previewIframeRef.current?.contentWindow?.location.reload();
before.mov

After

await previewIframeRef.current?.contentWindow?.queryClient.invalidateQueries({queryKey:['formLayouts']});
after.mov
@framitdavid
Copy link
Collaborator

I believe that @olemartinorg from Team Apps had some thoughts on how we, together with them, could solve this issue. In any case, it's wise to coordinate how we can address this together with Team Apps to make it as seamless as possible. 🙌

@olemartinorg
Copy link
Contributor

Yup, our issue on this is here:

@mlqn mlqn added area/app-preview Area: Related to test and preview of apps that are developed in Altinn Studio. kind/chore status/ready-for-specification Status: Used for issues that are ready for functional decription og detailed design. labels Mar 15, 2024
@nkylstad
Copy link
Member

@olemartinorg Any idea on the timeline on adapting app-frontend for Studio?

If we are talking weeks or months then we might as well implement the suggestion in this issue in the meantime - it looks and behaves a lot smoother than what we have today and looks like a relatively small fix for a big impact 😊 What do you thinkg @framitdavid?

@olemartinorg
Copy link
Contributor

We haven't prioritized it in team apps yet, AFAIK. I've been thinking we should simply add some convenience functions for you to use so we have 'official' support for stuff like this. The implementation would go something like you've suggested here in this issue anyway, so this more direct approach may work just as well.

We do something similar in our Cypress tests to quickly change the layout while running an app: https://github.com/Altinn/app-frontend-react/blob/b4e3f6e17d89a68e859c0c96bdebe4de9f21bd5b/test/e2e/support/custom.ts#L455C23-L478

Beware that we actually also put the layoutSetId in the cache key. I'm not sure if invalidating queries directly also invalidates queries with more specific keys, so that's why we made this a bit more complex in the cypress code linked above.

@framitdavid
Copy link
Collaborator

@olemartinorg Any idea on the timeline on adapting app-frontend for Studio?

If we are talking weeks or months then we might as well implement the suggestion in this issue in the meantime - it looks and behaves a lot smoother than what we have today and looks like a relatively small fix for a big impact 😊 What do you thinkg @framitdavid?

@nkylstad I agree that we could adapt the suggestion in the issue description as the first version, but we need to verify that it works as expected due to layoutSetId @olemartinorg mentioned. Their Cypress implementation could be used as inspiration to solve the potential layoutSetId cache key issue. 🤔

@framitdavid
Copy link
Collaborator

framitdavid commented Mar 15, 2024

@mlqn just saying, it is quite smart to use the query client on the Window object! 👏 I have never thought that was possible.

@mlqn
Copy link
Contributor Author

mlqn commented Mar 15, 2024

I used formLayouts as the cache key in my tests, so I can confirm that it also work with queries that use a layoutSetId. I also checked the documentation just to be sure, and it says:

// Invalidate every query with a key that starts with todos
queryClient.invalidateQueries({ queryKey: ['todos'] })

https://tanstack.com/query/v4/docs/framework/react/guides/query-invalidation

But I used formLayouts just for simplicity. It would be better to include the layoutSetId to invalidate only the current layout and not all layouts.

@olemartinorg
Copy link
Contributor

Sounds like we can simplify our cypress code as well, then.. 😉

just saying, it is quite smart to use the query client on the Window object!

Ditto! Although we primarily exposed if for Cypress testing purposes, and we didn't anticipate anyone using it for something else.. 🤔 I'll add a comment in our code to make sure we don't just remove it some day when rewriting something, as it will now be referenced outside our project.

@mlqn
Copy link
Contributor Author

mlqn commented Mar 15, 2024

@framitdavid Thanks 🙌 I didn't think it was possible either lol. I just thought it would be cool if it were possible, and then I found a post where the object was available in the window object! 🤯

@mlqn
Copy link
Contributor Author

mlqn commented Mar 15, 2024

@olemartinorg Oh I see, the object wasn't available by default, you added it in the window 🤔 So maybe it's not an ideal solution after all 🤔

@olemartinorg
Copy link
Contributor

No, go ahead! I support this effort 100% - I'll just add a notice about that in our code. Not having to maintain functions that wrap this makes it a bit easier on our part. I trust you to figure out tanstack query.

@mlqn mlqn self-assigned this Mar 18, 2024
@mlqn mlqn moved this to 👷 In Progress in Team Studio Mar 18, 2024
@mlqn mlqn moved this from 👷 In Progress to 🔎 Review in Team Studio Mar 27, 2024
@mlqn mlqn removed their assignment Mar 27, 2024
@mlqn mlqn linked a pull request Apr 1, 2024 that will close this issue
3 tasks
@nkylstad nkylstad added status/ready-for-dev Status: Used for issues that are ready for development. Has been through grooming. and removed status/ready-for-specification Status: Used for issues that are ready for functional decription og detailed design. labels Apr 3, 2024
@github-project-automation github-project-automation bot moved this from 🔎 Review to 🧪 Test in Team Studio Apr 5, 2024
@mlqn mlqn removed their assignment Apr 5, 2024
@lassopicasso lassopicasso self-assigned this Apr 8, 2024
@lassopicasso
Copy link
Contributor

Tested in dev - OK :)

@lassopicasso lassopicasso moved this from 🧪 Test to ✅ Done in Team Studio Apr 8, 2024
@lassopicasso lassopicasso removed their assignment Apr 8, 2024
@mlqn mlqn mentioned this issue Apr 15, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/app-preview Area: Related to test and preview of apps that are developed in Altinn Studio. kind/chore status/ready-for-dev Status: Used for issues that are ready for development. Has been through grooming.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants