Skip to content

iD failing on staging #388

Closed
Closed

Description

@danrademacher

Failure is here upon trying to load:
image

Uncaught TypeError: iD.utilDetect is not a function

I think the first thing we want to check is if this is loading our iD or a plain/default OSM iD, so we're debugging in the right place.

Activity

  1. added
    branch management
    on Jun 13, 2022
  2. danrademacher commented on Jun 13, 2022

    @danrademacher
    Author

    I suspect this is a simple fix. In the Vendorfile in staging branch we have:
    https://github.com/OpenHistoricalMap/ohm-website/blob/staging/Vendorfile#L54
    from 'https://github.com/openhistoricalmap/iD', :branch => 'release' do

    In the Vendorfile on merge-osm-website we have:
    https://github.com/OpenHistoricalMap/ohm-website/blob/merge-osm-website/Vendorfile#L28
    from 'https://github.com/openstreetmap/iD', :branch => 'release' do

    I would expect that changing openstreetmap to openhistoricalmap in the branch Vendorfile and rerunning build should fix this.

  3. added a commit that references this issue on Jun 13, 2022
  4. danrademacher commented on Jun 14, 2022

    @danrademacher
    Author

    Well, darn. that easy fix doesn't seem to have done the trick.

    I just pushed this commit to Staging, OpenHistoricalMap/ohm-website@b148a04, which includes pointing at correct iD and also other changes we have made.

    Same error: Uncaught TypeError: iD.utilDetect is not a function

    I think this is going to end up not being an issue with our iD code but instead that the new OSM website code is somehow loading iD differently, but I'm not sure yet.

    The iframe target for iD is https://staging.openhistoricalmap.org/id, and we see the same error there. On prod, https://openhistoricalmap.org/id works fine.

    In theory both are getting iD from the same place, base don this vendorfile:
    https://github.com/OpenHistoricalMap/ohm-website/blob/production/Vendorfile#L53-L59

    But looking more closely at that VENDORFILE, it seems like it's all getting subsidiary bits of code, and not the iD.js itself. I wonder if there's another place where that is specified. I'll keep poking at this.

  5. Dimitar5555 commented on Jun 14, 2022

    @Dimitar5555

    It looks like the problem could be the iD version that is being pulled. I see that there are differences in the file names for iD and their sizes compared to the their counterparts on the main OHM site.

  6. Dimitar5555 commented on Jun 14, 2022

    @Dimitar5555

    Also, the staging version is pointing to dist/iD.legacy.js instead of dist/iD.js. I'm not sure if that's on purpose.

    https://github.com/OpenHistoricalMap/ohm-website/blob/b148a04c3b5f5167db7386abff8c7934fad6ee58/Vendorfile#L41

  7. danrademacher commented on Jun 14, 2022

    @danrademacher
    Author

    Aha I was just typing that same thing!

    Now I see that the VENDORFILE is the place where we put the main JS in place as well:
    https://github.com/OpenHistoricalMap/ohm-website/blob/production/Vendorfile#L67

    But interestingly, the VENDORFILE on our upstream branch references a different source file:
    https://github.com/OpenHistoricalMap/ohm-website/blob/merge-osm-website-gin20220525/Vendorfile#L41

  8. added a commit that references this issue on Jun 14, 2022
  9. danrademacher commented on Jun 14, 2022

    @danrademacher
    Author

    Well, that didn't fix it either. Same error, and also I notice the size difference you saw, with production iD at 600K and staging at 1MB+
    image

    Also noting that staging is failing to load the additional other files (Mapillary and Pannelium)

  10. danrademacher commented on Jun 14, 2022

    @danrademacher
    Author

    In our local dev environment, iD has been accessible int he past (before upstream catchup that we're working on in this ticket). Now we get a 500 error that's entirely different from what we see on Staging, as if the /id route doesn't existing locally:
    image

  11. danrademacher commented on Jun 14, 2022

    @danrademacher
    Author

    Setting aside local dev issue for now, I suspect there's some sort of cache issue happening on staging where maybe we're not getting new code based on changes in the vendorfile.

    These two code blocks are now identical:

    1. Deployed to Production https://github.com/OpenHistoricalMap/ohm-website/blob/production/Vendorfile#L53-L69
    2. Deployed to Staging: https://github.com/OpenHistoricalMap/ohm-website/blob/merge-osm-website-gin20220525/Vendorfile#L27-L43

    But the ID files they are loading are not identical. Comparing

    image

    Reading compiled/minified code is not my strong suit so I'm not trying to debug these, but really they should be the same since they are supposedly coming from the same source

  12. Dimitar5555 commented on Jun 15, 2022

    @Dimitar5555

    The iframe on staging has src=https://staging.openhistoricalmap.org/id while on production it is https://openhistoricalmap.org/id. Removing staging. seems to resolve the issue (despite iD not being loaded because of some browser settings).

  13. danrademacher commented on Jun 17, 2022

    @danrademacher
    Author

    It is expected that the production OHM uses Production iD (https://openhistoricalmap.org/id) and the staging OHM uses Staging iD (https://staging.openhistoricalmap.org/id). Both should work and the fact that Staging iD doesn't work means we cannot roll the staging code out to production until we get it to work.

    It also previous has worked in local dev, so I'm starting there now -- getting to work locally, then hopefully that will lead to fixing it on staging, which will mean we can eventually deploy staging code with new OSM website code to the production site.

    So, back to local dev debugging. Looking at the local logs with the 500 error, we have:

    I, [2022-06-17T20:54:20.887679 #35]  INFO -- : [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] Started GET "/id" for 172.22.0.1 at 2022-06-17 20:54:20 +0000
    I, [2022-06-17T20:54:20.890167 #35]  INFO -- : [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] Processing by SiteController#id as HTML
    I, [2022-06-17T20:54:21.259267 #35]  INFO -- : [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]   Rendered site/id.html.erb (Duration: 89.0ms | Allocations: 868)
    I, [2022-06-17T20:54:21.262952 #35]  INFO -- : [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] Completed 500 Internal Server Error in 371ms (ActiveRecord: 265.1ms | Allocations: 2862)
    F, [2022-06-17T20:54:21.268172 #35] FATAL -- : [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] ActionView::Template::Error (undefined method `access_token_for_user' for nil:NilClass):
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]     10: <body>
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]     11: <% data = {}
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]     12:    if Settings.key?(:id_key)
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]     13:      token = current_user.access_token(Settings.id_key)
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]     14:      data[:token] = token.token
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]     15:      data[:token_secret] = token.secret
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]     16:      data[:consumer_key] = token.client_application.key
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] app/models/user.rb:346:in `access_token'
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] app/views/site/id.html.erb:13
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] app/controllers/site_controller.rb:125:in `id'
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] config/initializers/compressed_requests.rb:27:in `call'
    [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] config/initializers/cors.rb:9:in `call'
    I, [2022-06-17T20:54:21.272729 #35]  INFO -- : [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] Processing by ErrorsController#internal_server_error as HTML
    I, [2022-06-17T20:54:21.275626 #35]  INFO -- : [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]   Rendered errors/internal_server_error.html.erb within layouts/error (Duration: 0.1ms | Allocations: 4)
    I, [2022-06-17T20:54:21.281669 #35]  INFO -- : [014c6fef-f0ee-407d-9355-f7fd3bfde7aa]   Rendered layout layouts/error.html.erb (Duration: 6.1ms | Allocations: 2241)
    I, [2022-06-17T20:54:21.283427 #35]  INFO -- : [014c6fef-f0ee-407d-9355-f7fd3bfde7aa] Completed 500 Internal Server Error in 9ms (Views: 8.0ms | ActiveRecord: 0.0ms | Allocations: 2444)
    I, [2022-06-17T20:54:21.312526 #35]  INFO -- : [8190193c-bc2c-47af-b745-793c3dc5ad6f] Started GET "/assets/errors-f22ac01f5c336b3c39aad5b6efe71abb4c85eaa779786e388c0f963caaa8f43e.css" for 172.22.0.1 at 2022-06-17 20:54:21 +0000
    I, [2022-06-17T20:54:21.345301 #35]  INFO -- : [841b43aa-fba3-4ab3-b046-a01924ed61d9] Started GET "/assets/osm_logo-4afddaae0230a5a46687fdc751ed256dfdccde144118cb02a7d7960f207a4b92.svg" for 172.22.0.1 at 2022-06-17 20:54:21 +0000

    OK, for local dev this turned out to be a RTFM scenario. Following the instructions at https://github.com/OpenHistoricalMap/ohm-website/blob/merge-osm-website/CONFIGURE.md#oauth-consumer-keys get us to the same place as we are on staging:
    iD.utilDetect is not a function

    At least now we can debug locally!

  14. danrademacher commented on Jun 17, 2022

    @danrademacher
    Author

    I still think we are simply not loading iD.js properly somehow.

    Based on this SO post, I tried rake assets:clobber to see if I just needed a complete rebuild of some sort.

    Naturally, this rendered my local env inoperable... Gah. I should have started with rake assets:clean

    Now, despite redoing all of Steps 5 and 6 here, I've got a nonfunctional local environment. Sigh

    rake aborted!
    Errno::ENOENT: No such file or directory @ rb_sysopen - /var/www/tmp/cache/assets/sprockets/v4.0.0/-J/-JIIFe-XlDjmZNt7l0ukVnyHL2bKXsmebFM9m8_y91I.cache.27360.672.828947
    

    For whatever reason, stopping my container and restarting it, then rerunning Steps 5 and 6 worked -- and as expected the assets precompile took way longer.

    Now everything is precompiled from scratch and...

    Same error!

    iD.utilDetect is not a function
    
  15. danrademacher commented on Jun 17, 2022

    @danrademacher
    Author

    I'll need to enlist others on my team to solve this. Since both production and staging vendorfiles should be pulling iD.js from the same source, I would expect the minified code to be the same, but it's just not.

    Local dev matches staging and also fails.

    So these two files differ:

    We can see that the definitions for function utilDetect look different:
    image

    I'm beyond the edges of my abilities in understanding when and how build artifacts can differ in ways that don't matter, but the fact that broken local and broken staging are the same, while working production is different certainly suggests this different is the immediate cause.

    What I have not yet divined is what is the underlying cause of the difference!

  16. Dimitar5555 commented on Jun 18, 2022

    @Dimitar5555

    Since iD version 2.20, the presets are hosted in a separate repository. The production server is using iD 2.18.5 and I assume that the staging server is using a newer version. I'm not sure if it can cause such a problem though. It might be a good idea to consult with one of the iD developers.

  17. danrademacher commented on Jun 22, 2022

    @danrademacher
    Author

    I spent some time on this with @gregallensworth and we've concluded that our best approach here is to get a plain version of the newest iD working with newest web code, then fold back in our changes to iD.

    @batpad one thing we noticed is that you committed to this folder last month, https://github.com/OpenHistoricalMap/ohm-website/tree/merge-osm-website/vendor/assets/iD

    Do you recall what the source of that replacement iD.js was?

    It seems to me that these lines in the Vendorfile do not do what I thought they would, which is to replace the contents of the vendor/iD folder with whatever is specified there. They must do that at some point, but not with any of the build or setup commands we are currently running as documented at https://github.com/OpenHistoricalMap/ohm-deploy/tree/new_web_version/images#setting-up-ohm-website-for-development-mode

  18. danrademacher commented on Jun 28, 2022

    @danrademacher
    Author

    OK, I made some progress here!

    Here's iD working on localhost:
    image

    This is the commit that "fixed" it: OpenHistoricalMap/ohm-website@5c115cd

    What I did:

    1. Checked out the upstream iD release locally and hand picked the files from this folder: https://github.com/openstreetmap/iD/tree/release/dist that should be automatically copied when the Vendorfile is run
    2. Hand-made the changes to image asset URLs that the Vendorfile should be doing automatically here

    So now we know that newest iD release works just fine with newest OSM website. No surprise there! Just a bit painful trying to make that be true in our code.

    Challenges remain:

    1. How can we get the Vendorfile to actually execute so that, for example, we could temporarily pull in OSM iD and deploy that to staging without the hacky steps above and then, soon, redeploy a version with our mods
    2. We need to figure out the git-fu to get a clean checkout of latest iD code, to which we could then apply our changes, which include presets and the date filter, including URL params for date filter.
  19. danrademacher commented on Jun 28, 2022

    @danrademacher
    Author

    Looking at updates we will need to redo:

    So basically we have:

    • Changes to presets, which now need to be made in a new repo
    • Implementation of start and end date filters, including input validation
  20. danrademacher commented on Jun 28, 2022

    @danrademacher
    Author

    OK, simple answer on the Vendorfile:
    https://github.com/OpenHistoricalMap/ohm-deploy/blob/main/images/web/Dockerfile#L133-L135

    so in the container, we do:

    rm -rf vendor/assets/iD
    vendorer
    

    and that looks like this:

    # rm -rf vendor/assets/iD
    # vendorer
    keeping vendor/assets/jquery/jquery.throttle-debounce.js
    keeping vendor/assets/leaflet/leaflet.contextmenu.js
    keeping vendor/assets/leaflet/leaflet.contextmenu.css
    keeping vendor/assets/leaflet/leaflet.locationfilter.css
    keeping vendor/assets/leaflet/leaflet.locationfilter.js
    keeping vendor/assets/leaflet/img
    keeping vendor/assets/leaflet/leaflet.osm.js
    keeping vendor/assets/leaflet/leaflet.polyline.js
    updating vendor/assets/iD/iD/data
    updating vendor/assets/iD/iD/img
    updating vendor/assets/iD/iD/locales
    updating vendor/assets/iD/iD/mapillary-js
    updating vendor/assets/iD/iD/pannellum-streetside
    updating vendor/assets/iD/iD.css.erb
    updating vendor/assets/iD/iD.js
    keeping vendor/assets/polyfill/es6.js
    

    And, wow, the OHM iD is working fine, with date filters! 🙄
    image

    If this is running automatically on ohm-deploy whenever we deploy, then my original fix at the top of this ticket should have worked!

  21. danrademacher commented on Jun 28, 2022

    @danrademacher
    Author

    Aha, I think I got it:

    1. MAIN Dockerfile reruns vendorer here: https://github.com/OpenHistoricalMap/ohm-deploy/blob/main/images/web/Dockerfile#L133-L135
    2. STAGING Dockerfile does not not contain the string vendor at all: https://github.com/OpenHistoricalMap/ohm-deploy/blob/staging/images/web/Dockerfile

    Those were removed here:
    OpenHistoricalMap/ohm-deploy@5eb6f44#diff-03a61f635e59ab9d93c26690c3d752b840586e60d16ad70fb6edd14bd6046a30L133-L135

    @Rub21 can you take a look at that and see why we removed the vendorer updates from the Staging Dockerfile? Can we just restore those few lines and redeploy?

    • Edited to add -- just just added them back OpenHistoricalMap/ohm-deploy@59121b6 and if that Action completes successfully, I am going to merge into staging and verify that iD is working again there.

    I think that might fix iD and unblock the upstream merge -- we might still want to catch up to latest iD, but we could then do that without it blocking the website catchup.

  22. added a commit that references this issue on Jun 28, 2022
  23. danrademacher commented on Jun 29, 2022

    @danrademacher
    Author

    OK, adding those back in worked and the job completed successfully:
    image

    I then merged that into staging so we'd have the latest there and see if iD works now.

    and voila:
    image

    So while we do need to update iD, the cause of this specific breakage is unrelated to iD version. It's that we had a broken version of the vendor files, and then we disabled the system that would overwrite them on each deploy.

    I will file a new, lower priority ticket for catching up with iD upstream, but that no longer needs to be a blocker on catching up with website upstream

    cc @batpad @Rub21

  24. added theissue type on Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

branch management

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions