question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello

I’m facing an issue with xprops passed down to a Zoid using a cross-domain. For some reason xprops has not been passed down. Does anyone have any thought ? It all relies inside the same domain.

Zoid Component:

import * as zoid from 'zoid/dist/zoid.frameworks';
import { PUBLISHER_URL } from '../config/config';

const ZoidComponent = zoid.create({
  tag: 'Trips-Publisher',
  url: getUrl(),
  containerTemplate: function containerTemplate({ doc, uid, frame, prerenderFrame }) {
    const container = doc.createElement('div');
    container.id = uid;
    frame.style.width = '-webkit-fill-available';
    frame.style.minWidth = '750px';
    frame.style.minHeight = '200px';
    frame.style.height = 'calc(90vh - 10px)';
    container.appendChild(frame);
    prerenderFrame.style.display = 'none';
    container.appendChild(prerenderFrame);
    return container;
  },
  prerenderTemplate: function containerTemplate({ doc }) {
    const html = doc.createElement('html');
    const p = doc.createElement('p');
    p.innerText = 'Please wait while the trips publisher loads...';
    html.appendChild(p);
    return html;
  },
  props: {
    bookingId: {
      type: 'string',
      required: true
    },
    openModal: {
      type: 'boolean'
    },
    handleCloseModal: {
      type: 'function'
    }
  }
});
export default ZoidComponent;

Calling the Component passing Paramenters

function App({ config = defaultConfig.toString() }: { config: string }): ReactElement {
  const parsedConfig: Config = JSON.parse(config);
  const [openModal, setOpenModal] = useState(false);

  useEffect(() => {
    const open = parsedConfig && parsedConfig.openModal === 'true';
    setOpenModal(open);
  }, [parsedConfig]);

  const handleCloseModal = () => {
    const callBack = parsedConfig.handleClose;
    if (callBack) {
      window.Function(callBack)();
    }
    setOpenModal(!openModal);
  }
  const ZoidReactComponent = ZoidComponent.driver('react', {
    React,
    ReactDOM
  });
  return (
    <div className="App">
      <header className="App-header">
        {parsedConfig && parsedConfig.openModal !== undefined && parsedConfig.bookingId && (
          <ZoidReactComponent bookingId={parsedConfig.bookingId} openModal={openModal} handleCloseModal={handleCloseModal} />  
        )}
      </header>
    </div>
  );
}

App.propTypes = {
  config: PropTypes.string
};


export default App;

Another Domain Business logic receiving the Props:

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import './react_dates_overrides.css';
import './config/i18next';
import 'typeface-roboto';
import 'react-dates/initialize';

import './config/moment';

import * as serviceWorker from './registerServiceWorker';
import ZoidComponent from './components/Integration/ZoidComponent';
import Main from './App';

import { initializeGA } from './config/googleAnalytics';
import AppProvider from './AppProvider';

initializeGA();

if (ZoidComponent) {
  // Initialization for Zoid Library
}
ReactDOM.render(
  <AppProvider>
    <Main {...window.xprops} />
  </AppProvider>,
  document.getElementById('root')
);

App.js

const App = ({ classes }) => {
  const WrappedIntegration = () => <Integration {...window.xprops} />;
  // eslint-disable-next-line no-console
  console.log('MAIN: window.xprops:', window.xprops);
  const oktaAuth = new OktaAuth(getOktaConfig());
  return (
    <BrowserRouter>
      <Security oktaAuth={oktaAuth} restoreOriginalUri={restoreOriginalUri}>
        <Suspense
          fallback={
            <div className={classes.loading}>
              <Typography>Please wait ...</Typography>
            </div>
          }
        >
          <Switch>
            <SecureRoute name="Integration" exact path={INTEGRATION} component={WrappedIntegration} />
            <SecureRoute
              name="IntegrationTest"
              exact
              path={INTEGRATION_TEST}
              component={IntegrationTest}
            />
            <Route exact path={INTEGRATION_CALLBACK} component={LoginCallBack} />
            <PrivateRoute path="/" key="app" component={Main} />
            <PublicRoute render={() => <Redirect to={LOGIN_ROUTE} />} />
          </Switch>
        </Suspense>
      </Security>
    </BrowserRouter>
  );
};

export default compose(
  withStyles(styles),
  DragDropContext(HTML5Backend)
)(App);

Integration.js

function Integration({
  classes,
  bookingIdPassed,
  getTokenByOktaToken,
  handleCloseModal,
  refreshApp,
  checkSession,
  auth,
  showError,
  ...props
}) {
  const { authState } = useOktaAuth();
  const history = useHistory();
  // eslint-disable-next-line no-console
  console.log('props:', props);
  // eslint-disable-next-line no-unused-vars
  const [xprops, setXProps] = useState(window.xprops);

  // SHOWING window.props passing by
  // eslint-disable-next-line no-console
  console.log('xprops:', window.xprops);
  return (<div>/div>);
  }

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jbpadilhacommented, Oct 11, 2021

I solved the issue changing the domains. But I was wondering if it could work in the same domain.

1reaction
dagjaneirocommented, Oct 11, 2021

I’m having the same issue. I believe it’s a bug introduced in 9.0.80, it started happening to me since I upgraded. It works fine for me with version 9.0.78.

Edit: I’m also using the same domain.

Read more comments on GitHub >

github_iconTop Results From Across the Web

window.xprops sporadically undefined in Firefox 68.0.1 #252
It seems that window.xprops is occasionally undefined for my components in Firefox 68.0.1 (it does work some of the time).
Read more >
Developers - xprops undefined - - Bountysource
Hello. I'm facing an issue with xprops passed down to a Zoid using a cross-domain. For some reason xprops has not been passed...
Read more >
React - TypeError: Cannot read property 'props' of undefined
I'm trying to create a click event be able to delete an item on my list, but when I click it I get...
Read more >
Ubuntu Manpage: xprop - property displayer for X
The xprop utility is for displaying window and font properties in an X server. ... If a property is not defined on the...
Read more >
zoid example - KrakenJS
I just need to use window.xprops to get the props that are passed down. <!-- Pull in the login component we defined above...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found