Open forsbergplustwo opened 10 months ago
Seeing the same on my side as well. Also Turbo Rails.
@forsbergplustwo @awd do you have a sample app that I can try?
We would expect that our application is included as it was originally with all JS files included, like a normal iframe would behave.
All of the missing js and template tag are expected in the modal iframe. Does this cause your <p>Modal content</p>
does not show?
Hey @henrytao-me - I'll try and create a sample app for you.
The modal content <p>Modal content</p>
does display, but none of our javascript is available within the modal content.
So the js and template tag are included, but they are not being activated or loaded, which breaks trying to use any of it within the modal content. Is that expected behaviour?
@henrytao-me - Here's an example Glitch project showing the issue: https://glitch.com/edit/#!/app-bridge-modal-js-example
Reproduction steps:
data-api-key
value in index.html
to your own Shopify App api keyscript.js
function iAmAvailable()
is never called when modal content is shown. This is the issue, no JS from app is available inside modal.This would be fine if we were only building little things like confirmation modals. However, with the fullscreen "max" modal, we are building things like this:
Which is not feasible without js libraries etc within the modal context.
Hi @forsbergplustwo my team is on Shopify Partners slack if you would like to pair on this. If you are not on slack yet, you can join from this link https://join.slack.com/t/shopifypartners/shared_invite/zt-2aqba1tg5-f5bJYYINfb7W1xQ9GcrjwA
@henrytao-me I'm on Slack 😊 How do you mean pair, is the sample not working for you?
For us the majority of our scripts run in the modal, however we can no longer add event listeners to the resulting document, i.e. document.addEventListener
no longer works
Update
The document events are being added, they're just being added to the main document
, not the new "modal" document
and as a result context is all broken and the event listeners inside the model no longer work as intended, and even some query selectors are not being found 😕
How can we run code in the load
event of ui-modal
and receive the appropriate context for the modal?
@forsbergplustwo your link does not load for me
A potential solution is to just load another iframe inside the modal reusing all query params and load up a fresh copy of app bridge in the modal like you used to load iframe modals in v3.x but change the routes content-security model to match.
This gives back the expected document context since we're in yet another new frame.
It's not elegent, there's massive "yo dawg i heard you like iframes" energy with this "fix" and it's probably not how the 4.x team expects us to use this but it seems to be working fine for my current needs so maybe it will work for you too.
<ui-modal id="complex-modal" variant="max">
<ui-title-bar title="Complex Max Modal"></ui-title-bar>
<iframe src="/complex-modal?{{ request.query }}" style="min-height: 100vh;"></iframe>
</ui-modal>
Describe the bug
When using the Modal
<ui-modal>
component of AppBridge v4 (CDN), the javascript files referenced in the<head>
of our Rails 7 application are not loaded inside the modal iframe, breaking all JS related behaviour for us.Of interest may be that Rails applications now by default use an
importmap
for loading JS files.Code used to launch Modal:
Original
<head>
of applicationResulting Modal
<head>
, which is missing all of the JS files from original:Issues:
Note: Within the Modal iframe (just after the closing
</head>
tag, there is a<template>
tag containing the removed javascript code, as well as the original body of the application.Content of
<template>
tag:Expected behaviour
We would expect that our application
is included as it was originally with all JS files included, like a normal iframe would behave.Contextual information
Packages and versions
List the relevant packages you’re using, and their versions. For example:
Platform
Additional context
Rails 7 application using Hotwire (Turbo, Stimulus etc.)